On Aug 9, 3:56 am, "ShoeShine" <Blishter....TakeThisOut@RemarkAble.com> wrote:
> hi,
>
> I'm trying to write a form-checking function that will ride "inside" a PHP
> page that "writes" out an HTML user-input form. Most of the other fields
> are checked fine by the PHP processor script, but I"m clueless in PHP so I'm
> attempting to insert a little email checker function in the "head" of my doc
> that is called by the onBlur function as soon as the focus has left the 2nd
> email input field.
That's your first mistake. Never do validation in an onblur event.
Validate when the form is submitted (onsubmit.)
>
> There's 2 email input fields, just to compare that the the correct email has
> been input, ie, one is exactly equal to the other.
>
> so the script in the HEAD looks like this:
>
> <script language="javascript" type="text/javascript">
> function chckEM() {
> if (form1.email2.value!=form1.email.value)
Use syntax like document.forms['form1'].elements['email2'] to
reference the elements.
> { alert("your email entries did not match ...");
> form1.email.focus();
See above. Also, this illustrates the problem of validating in the
onblur event. What if a user first focuses the email2 element, enters
an address and then attempts to focus the email element? At best they
will get a useless alert.
> return false;
Why are you returning false here? It makes no sense considering that
you focused the email element.
> }
> return true;
> }
> </script>
>
> and it's called by the onBlur in the 2nd email field like this:
>
> <input name="email2" type="text" size="40" maxlength="40"
> onBlur="chckEM();">
>