8th Css
8th Css
Code.
1. Onload Events
<html>
<head>Javascript Events</head>
</br>
<body onload="window.alert('Page successfully loaded');">
<script>
document.write("The page is loaded successfully");
</script>
</body>
</html>
Output
Client side Scripting Language (22519)
2. On Change :
<!DOCTYPE html>
<html>
<body>
<p>Select a new car from the list.</p>
<select id="mySelect" onchange="myFunction()">
<option value="Audi">Audi</option>
<option value="BMW">BMW</option>
<option value="Mercedes">Mercedes</option>
<option value="Volvo">Volvo</option>
</select>
<p>When you select a new car, a function is triggered which outputs the value
of the selected car.</p>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("mySelect").value;
document.getElementById("demo").innerHTML = "You selected: " + x;
}
</script>
</body>
</html>
Output
Client side Scripting Language (22519)
3. On color change
<!DOCTYPE html>
<html>
<head>
<h1> Color change</h1>
<style>
input[type="radio"] {
margin-right: 10px;
}
input[type="text"] {
padding: 5px;
width: 200px;
}
</style>
</head>
<body>
<h1>Choose a Color:</h1>
<form>
<label><input type="radio" name="color" value="red"> Red</label>
<label><input type="radio" name="color" value="green"> Green</label>
<label><input type="radio" name="color" value="blue"> Blue</label>
</form>
<br>
<input type="text" id="colorInput" placeholder="Type something...">
<script>
// Get references to the radio buttons and the text input
const redRadio = document.querySelector('input[value="red"]');
const greenRadio = document.querySelector('input[value="green"]');
const blueRadio = document.querySelector('input[value="blue"]');
const colorInput = document.getElementById('colorInput');
redRadio.addEventListener('change', function() {
if (this.checked) {
colorInput.style.backgroundColor = 'red';
}
Client side Scripting Language (22519)
});
greenRadio.addEventListener('change', function() {
if (this.checked) {
colorInput.style.backgroundColor = 'green';
}
});
blueRadio.addEventListener('change', function() {
if (this.checked) {
colorInput.style.backgroundColor = 'blue';
}
});
</script>
</body>
</html>
Output
4. Key up
<!DOCTYPE html>
<html>
<head>
Client side Scripting Language (22519)
<!DOCTYPE html>
<html>
Client side Scripting Language (22519)
<head>
<title>Form Events</title>
<script>
function handleSubmit(event) {
event.preventDefault();
alert('Form submitted!');
}
function handleReset() {
alert('Form reset!');
}
</script>
</head>
<body>
<form onsubmit="handleSubmit(event)" onreset="handleReset()">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<br>
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<br>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
Output