How to check form validation by javascript

Hello
Now, I am ready to show how to check form validation by using javascript. Its a primary stage of a javascript prorgammer. Lets go-

<!DOCTYPE html>
<html>
<head>
<title>Learn JavaScrtipt</title>

<script>
/*

var x = window.confirm(“Are you sure to delete this?”);

if(x){

window.alert(“Your data is goting to delete.”);

}else{

window.location = “https://tisuchi.wordpress.com&#8221;;
}

*/

/*
function emailchk(){
var x = document.aa.bb.value;

if(x.indexOf(“@”) == -1){
alert(“Please entair a valid email address”);
}
document.aa.bb.focus();
}
*/
function validation(){

if(document.formname.name.value==””)
{
alert (“Please enter User Name”)
document.formname.name.focus();
return false;
}
}
</script>
</head>

<body>

<form name=”formname” method=”POST” onsubmit=”return validation()”>
<input type=”text” name=”name” value=”” placeholder=”Type your name” ><br/>
<input type=”text” name=”email” value=”” placeholder=”Type your email” ><br/>
<input type=”submit” name=”email” value=”Submit Now”>
</form>
</body>
</html>

Save this file and run it. It will check if any field will be blank. Thanks for reading.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s