In Association with Amazon.in   Flipkart

Tuesday, November 19, 2013

JavaScript OnBlur Event Example

JavaScript OnBlur Event: When control jumps from current object then onBlur event function called automatically.

Example:

<html>
<head>
<script>
function f1(len)
{
if(len<6)
{
document.getElementById('un').style.background="red";
alert("User name should be >6");
document.getElementById('un').value="";
document.getElementById('un').focus();
}
else
document.getElementById('un').style.backgroundColor='yellow';
}
</script>
</head>
<body>
<form>
User Name:
<input type="text" name="unm" id="un" onBlur="f1(this.value.length);"> <br>
Password:
<input type="password" name="pwd" id="pw" onBlur="if((this.value).length<6) { this.style.backgroundColor='red'; alert('Password should be grater then 6');}">
</form>
</body>
</html>


Output:
User Name:
Password:

No comments:

Post a Comment


Related Posts Plugin for WordPress, Blogger...