String Length
Posted: Mon Mar 29, 2010 11:36 am
Hi guys,
I don't know much about JavaScript but having a go at validating form input. I can check whether the user has entered anything but struggling with string length.
The code:
[text]
<form action="register.php" onsubmit="return validate_registration(this);" method="post">
<b>Password:</b><br />
<input type="password" size="20" name="password"> <br /><br />
<input type="submit" name="submit" value="Continue">
</form>
[/text]
[text]
function validate_registration (field)
{
if (field.password.value.length > 40)
{
alert ("Your password must be 40 characters or less.");
field.password.focus();
return false;
}
else
{
return true;
}
}
[/text]
Any idea why it isn't working?
I don't know much about JavaScript but having a go at validating form input. I can check whether the user has entered anything but struggling with string length.
The code:
[text]
<form action="register.php" onsubmit="return validate_registration(this);" method="post">
<b>Password:</b><br />
<input type="password" size="20" name="password"> <br /><br />
<input type="submit" name="submit" value="Continue">
</form>
[/text]
[text]
function validate_registration (field)
{
if (field.password.value.length > 40)
{
alert ("Your password must be 40 characters or less.");
field.password.focus();
return false;
}
else
{
return true;
}
}
[/text]
Any idea why it isn't working?