You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Patrick Refondini <pa...@jpnet.ch> on 2002/02/01 13:10:53 UTC
Re: OT: onblur Javascript validation
Hi Todd,
No idea:
I cannot answer your question :( as I do not code Javascript.
But suggestion:
I can deal with Javascript validations for required fields, dates, ...
since I found Struts Validator :)
http://home.earthlink.net/~dwinterfeldt/
I found it worth the invested time
Regards, Patrick
Todd G. Nist wrote:
>Hello all,
>
>I have a small Javascript function for validating if a field is required or
>not. I would like to use it with the "onblur" attribute on the html tag.
>If the field is empty, then I would like to reapply focus to the filed and
>display a message to the user forcing them to fill in the field. Additional
>validation will be added in the future via regular expressions to ensure
>that the data type is correct.
>
>PROBLEM:
>
>When I go to leave the field the "blur" event firers and I see the message
>'Mandatory field.....'. I then apply focus back to the requesting field and
>return 'false' which I thought would prevent the passing of "focus" to the
>next field; this was however wrong. What happens is it just goes between
>the two fields display the message 'Mandatory field.....' until I kill the
>browser (IE 5.5).
>
>So the basic code looks like this:
>
><script language="Javascript">
>function checkValue(field, required, regFormat) {
>
> if (field.value!="") {
> return true;
> }
>
> if (required) {
> alert('Mandatory field. Place field specific message here....');
> field.focus();
> return false;
> }
>
> return true;
>}
>
></script>
>
><BODY>
><FORM validate=onsubmit="alert('submitted');return false;">
><HR>
><TABLE>
> <TR>
> <TD colspan="2">
> <TABLE>
> <TR>
> <TD>Date before <SMALL>MM/DD/YYYY</SMALL>:</TD>
> <TD><INPUT type="text" name="before" onblur="checkValue(this,
>true, '');"></TD>
> </TR>
> <TR>
> <TD>Date After <SMALL>MM/DD/YYYY</SMALL>:</TD>
> <TD><INPUT type="text" name="after" onblur="checkValue(this, true,
>'');"></TD>
> </TR>
> </TABLE>
> </TD>
> </TR>
></TABLE>
>
>
>Any ideas or suggestions are appreciated.
>
>
>Regards,
>Todd G. Nist
>Email: tnist@fbos.com
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>