struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Refondini <>
Subject Re: OT: onblur Javascript validation
Date Fri, 01 Feb 2002 12:10:53 GMT
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 :)

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.
>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;
><FORM validate=onsubmit="alert('submitted');return false;">
>  <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,
>        </TR>
>      </TABLE>
>    </TD>
>  </TR>
>Any ideas or suggestions are appreciated.
>Todd G. Nist

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message