Click to See Complete Forum and Search --> : Form Validation


leonard905
03-10-2004, 03:59 PM
Hi,

I have a form with 2 fileds: username and password. I want to validate null values in either field and return an error message. How can I do this.

Thanks,
Leo

steelersfan88
03-10-2004, 04:03 PM
<script type="text/javascript">

function checkVals() {
var user = document.forms[0].userNm.value
var pass = document.forms[0].passWd.value
var minLength = 1 // minimum length for accept

if(user < minLength || pass < minLength) {
alert("Fields not entered")
return false;
}
else {
return true;
}
}

</script>

<form name="myForm" onsubmit="return checkVals()">
User Name: <input type="text" name="userNm"><BR>
Password: <input type="password" name="passWd"><BR><BR>
<input type="submit" value="Submit!">
</form>That should do it, if no one already posted!