FORM EVENTS
html file
<!DOCTYPE html>
<html lang="en">
<head>
<title>Form Events</title>
</head>
<body>
<form action="" onsubmit="submitFunction()">
<label for="">Name</label><input type="text" id="fname" onchange="onchangeFunction(this)" onselect="selectFunction()" oninvalid="alert('Please fill the First Name.')" required><br><br>
<label for="">Class</label><input type="text" id="" ><br><br>
<select id="" onchange="onchangeFunction(this)">
<option value="India">India</option>
<option value="Pakistan">Pakistan</option>
<option value="Bangladesh">Bangladesh</option>
<option value="Sri Lanka">Sri Lanka</option>
<option value="Nepal">Nepal</option>
</select>
<input type="submit">
</form>
<div id="test" style="border:1px solid red;margin-top:20px;"></div>
<script>
function focusFunction(element){
element.style.background = "lime";
}
function blurFunction(element){
element.style.background = "";
}
function inputFunction(element){
var x = element.value;
document.getElementById("test").innerHTML = x;
}
function onchangeFunction(element){
var x = element.value;
document.getElementById("test").innerHTML = x;
}
function selectFunction(){
console.log("You selected some text.");
}
function submitFunction(){
var x = document.getElementById("fname").value;
alert("Hello " + x);
}
</script>
</body>
</html>