Thursday, August 7, 2014

JavaScript validation

In the below code of html and JavaScript ,the username must not be empty and password must not be empty.One more validation is that username and password must not be same.This is used for log in and form validation .

Copy the below code and paste in notepad and save it with .html extension and open it in  browser and it will definitely work.
<script type="text/javascript">
function validate(){  var  username=document.getElementById  ("txtusername").value;var password=document.getElementById ("txtpassword").value;if(username.length==0){   alert("username must not be empty");   }if(password.length==0){   alert("password must not be empty");    }if(username==password){alert("username and password must not be same");}
<form name="f1">Enter UserName:-<input type="text" id="txtusername"><br>Enter Password:-<input type="password" id="txtpassword"><br><input type="submit" value="signin" onclick="validate()"></form>
Categories: ,


Post a Comment