Onblur event triggered when field loses focus. This event is mainly use to validate the field when user moves to another field to fill the values.
How To Check The Value Of Input Field On onblur event
First create one input field. This input field is validated through javascript when field loses focus. On onblur event we call validate_me function.
1 |
<input id="username" type="text" name="username" onblur="validate_me(this);" /> |
Validate_me Function
1 2 3 4 5 6 7 |
function validate_me(username){ if(username.value.length==0){ // If entered value count is 0 alert("Please enter a value"); return false; } return true; } |
If the field is empty and user moves to another field then alert message occurs which ask user to enter a value.