[thelist] Simple Javascript field checking
Christian Heilmann
lists at onlinetools.org
Thu Feb 24 13:58:10 CST 2005
Brian Cummiskey wrote:
> 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.
>
Yes it is, but you can have both. What you should do to make it failsafe
(of course with a backend script to fall back on) is to call your script
onsubmit on the form not onclick of a button. Your example would make
the button useless when there is no scripting available.
More information about the thelist
mailing list