|
JAVASCRIPT SCRIPTS » FORMS » EMPTY FIELD VALIDATION IN JAVASCRIPT |
EMPTY FIELD VALIDATION IN JAVASCRIPT - FORMS |
| |
|
How to validate empty field in forms using javascripts
Sometimes empty form fields validation is most unpleasant when you use validation in php (although it is much safer). Therefore, for the interaction to be more pleasant for the user but also to save resources ( PHP language uses server resources and javascript browser for decoding ) will use a simple and efficient validation script in javascript.
Here is the script:
Copy this javascript in <head> section of your page
=================
<script>
function validare(){
if(document.form.mail.value=="")
{
alert("Sory! You can submit empty values for mail input!");
return false;
}}
</script>
=======================
And the used form:
===============
<form action="" method="post" name="form">
<input name="mail" type="text" />
<input name="" type="submit" onClick="return validare()" value="Submit"/>
</form>
===============
EXAMPLE (click submit button to see the javascript in action)
|
|
|
|
|
|
|