8. Write Ajax program to carry out validation for a username
entered in textbox. If the textbox is blank, print ‘Enter username’. If the
number of characters is less than three, print’ Username is too short’. If
value entered is appropriate the print ‘Valid username’.
Html file :
<html>
<head>
<script
type="text/javascript">
function
val_user(str)
{
var
ob=false;
ob=new
XMLHttpRequest();
if(str=="")
document.getElementById("a").innerHTML="Username
Should not be Empty"; else
if(str.length<=3)
document.getElementById('a').innerHTML="lenght
is too short";
else
document.getElementById('a').innerHTML="valid username";
}
</script>
</head>
<body>
<form>
<table align="center">
<tr><td><b>Enter
Username : </b></td><td><input type=text
name=u_name id=u_name></td></tr>
<tr><td></td><td><font
color="red" size=3><span id=a></span></font></td></tr>
<tr><th
colspan="2"><input type=button value=submit
onclick="val_user(form.u_name.value)"></th></tr>
</table>
</form>
</body>
</html>
No comments:
Post a Comment
Note: only a member of this blog may post a comment.