Trying to learn JavaScript, makin decent progress I guess, but I’m stuck at validating a form, tried to see if anybody has the same problem, search didn’t turn anything up. So would you please help me?
var minlength = 6;
var pwlength = document.getElementById('psswrd');
var invalid = " ";
function validate() {
if (pwlength.length < minlength && pwlength == invalid) {
alert("Password not valid");
else {
alert("Password okay!");
}
}
submitbtn.onClick = validate();
document.forms[0].submitbtndocument.getElementById("submitbtn")ordocument.getElementsByName("submitbtn")[0]will work depending on how you name or ID the button HOWEVER do not assign onclick handlers to submit buttons, instead assign submit handler to the formI have taken the trim from here
and I assume the form has ID=”form1″