Thursday 10 November 2016

JavaScript validation with image

<html>
<body>
<script type="text/javascript">
function validate(){
var name=document.f1.name.value;
var passwordlength=document.f1.password.value.length;
var status=false;
if(name==""){
document.getElementById("namelocation").innerHTML=
" <img src=''/> Please enter your name";
status=false;
}else{
document.getElementById("namelocation").innerHTML=" <img src=''/>";
status=true;
}
 
if(passwordlength<6){
document.getElementById("passwordlocation").innerHTML=
" <img src=''/> Password must be greater than 6";
status=false;
}else{
document.getElementById("passwordlocation").innerHTML=" <img src=''/>";
}
 
return status;
}
</script>
<form name="f1" action="" onsubmit="return validate()">
<table>
<tr><td>Name:</td><td><input type="text" name="name"/>
<span id="namelocation" style="color:red"></span></td></tr>
<tr><td>Password:</td><td><input type="password" name="password"/>
<span id="passwordlocation" style="color:red"></span></td></tr>
<tr><td colspan="2"><input type="submit" value="register"/>  </td></tr>
</table>
</form>
</body>
</html>

No comments:

Post a Comment