JavaScript Forms Validation


Prev Tutorial Next Tutorial

JavaScript Forms Validation

Forms validation is important things other wise user input wrong data, so we need to validate given data by user before submit it on server.

The JavaScript provides the facility to validate the form on the client side so processing will be fast than server-side validation. So, most of the web developers prefer client side form validation using JavaScript.

Here i will show you how to validate any input field like user name can not be blank. In below example input are can not be blank.

Example

<html>
<head>
<script>  
function form_validation(){  
var name=document.myform.name.value;  

//var x = document.forms["myform"]["name"].value;
  
if (name==null || name==""){  
  alert("Name can't be blank");  
  return false;  
}  
}
</script>  
</head>

<body>  
<form name="myform" method="post" action="register.php" onsubmit="return form_validation()" >  
Name: <input type="text" name="name">  
<input type="submit" value="submit">  
</form>  
</body>
</html>

Result

Name:

Prev Tutorial Next Tutorial

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain, Tutorialday.com, SeosmoTools.com @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: hitesh.xc@gmail.com WhatsApp no. 8882538826

Yahoo Advertisements