Hi, I have this code and I can’t get it to work. I’m new with Ajax jQuery and JavaScript so please be nice 🙂 and thank you for the help 🙂
This code should be a simple form validation but when I tab in to the next input box it does nothing. It should be displaying an error message that the uname is less than 5 characters long. Thank you!
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function validateUsername(){
var uname=document.getElementById("uname").value;
if(uname<5){
document.getElementById("errormsg").value = "wait";
}
}
</script>
<body>
<form method=post id=regform action=jscript.html>
<table>
<tr>
<td>Username</td>
<td><input type=text name=uname id=uname onBlur="javascript:validateUsername()"/></td>
<td><input type=hidden name=errormsg value='' id=errormsg"/></td>
</tr>
<tr>
<td>Password</td>
<td><input type=text name=uname id=uname onBlur="javascript:validatePassword()"/></td>
<td><input type=hidden name=errormsg value='' id=errormsg"/></td>
</tr>
</table>
</form>
try this, i hope it will help.
You need to improve your html, put quotes around value of every attribute like type=”text” name=”uname” and all you was writing is javascript, not jquery, so you also not need to include that .js file.
in your function validateUsername, uname holds the number of characters entered by user, and if its less then 5, then errormsg (which is id of a div) will show wait msg
you don’t need input type=”hidden” to show error message to user, use DIV or SPAN for that