[thelist] Simple Javascript field checking

Brian Cummiskey Brian at hondaswap.com
Thu Feb 24 12:11:25 CST 2005


john at johnallsopp.co.uk wrote:

>>>
>>>function checkEmail()
>>>{
>>>        if
>>>(document.registrationForm.regEmail!=document.registrationForm.regEmail2)
>>>        {
>>>                alert ("Emails not the same");
>>>                return false;
>>>        }
>>>        return true;
>>>}
>>>

> <tr>
>   <td>Email: </td>
>   <td><input type="text" name="regEmail"></td>
> </tr>
> <tr>
>   <td>Email (repeat): </td>
>   <td><input type="text" name="regEmail2" onBlur="checkEmail();"></td>
> </tr>
> 


This is not a fail safe.  Theres a good chance I typo'ed the FIRST 
email, not the second, so when i go back and change the first and leave 
the 2nd alone, nothing gets checked.

I would wait until the form is being submitted to check anything.

<input type="button" onclick="checkform()"; />

function checkform() {
	if !(checkEmail())
	{
	alert "blah"
	retrun false;
	}
	else
	//submit the form...
	document.registrationFrom.submit();
}


and even more so, the enitre thing fails if JS is disabled.

Server-side is the only way to be certain.





More information about the thelist mailing list