onload Event:
The event shows some javascript instruction while the webpage is loading:
Example:
<!DOCTYPE html>
<html>
<head>
<title>InputFromUser</title>
<script type= "text/javascript">
function Input(){
var Username = document.getElementById("text").value;
alert("Successfully signed up!");
}
</script>
</head>
<body onload = "alert('The page has loaded successfully');">
<input id="text" placeholder= "Username">
<button onClick = "Input();">SignUp</button>
</body>
</html>
onblur Event:
The event is very useful.It allows some action to happen when the user clicks away from a form field or other element that they had just previously been in. It's useful for providing feedback to a user based on their input - in a way, it can be used as a less obtrusive from of an alert for certain things.
Example:
<!DOCTYPE html>
<html>
<head>
<title>InputFromUser</title>
<script type= "text/javascript">
function Input(){
var Username = document.getElementById("text1").value;
alert("Successfully signed up!");
}
function checkfield(){
var Username = document.getElementById("text1").value;
if(Username.length<2){
document.getElementById("message").innerHTML="Tooshort";}
}
</script>
</head>
<body onload = "alert('The page has loaded successfully');"> <span id="message"></span>
<input id="text1" type="text" onblur="checkfield();">
<button onClick = "Input();">SignUp</button>
</body>
</html>
0 Comments