I realize this reply is probably best suited to a Javascript newsgroup, but in reply to a previous posting, the below code will handle the "onblur Javascript validation" issue (may not be pretty, but it works) :
---------------------------------------------------- <script language="Javascript"> var currField = null; function checkValue(field, required, regFormat) { if ((required) && (field.value == "")) { alert(field.name + ' is mandatory'); return false; } return true; } function preCheckValue(field, required, regFormat) { if ((currField != null) && (currField == field)) { if (!checkValue(field, required, regFormat)) { field.focus(); } else { currField = null; } } else if (currField == null) { currField = field; preCheckValue(field, required, regFormat); } } </script> <BODY> <FORM> <HR> <TABLE> <TR> <TD colspan="2"> <TABLE> <TR> <TD>a:</TD> <TD><INPUT type="text" name="a" onblur="preCheckValue(this, true, '');"></TD> </TR> <TR> <TD>b:</TD> <TD><INPUT type="text" name="b" onblur="preCheckValue(this, true, '');"></TD> </TR> </TABLE> </TD> </TR> </TABLE> ---------------------------------------------------------------- >From: Patrick Refondini <[EMAIL PROTECTED]> >Reply-To: [EMAIL PROTECTED] >To: Struts Users Mailing List <[EMAIL PROTECTED]> >Subject: Re: OT: onblur Javascript validation >Date: Fri, 01 Feb 2002 13:10:53 +0100 > >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: [EMAIL PROTECTED] >> > > > >-- >To unsubscribe, e-mail: ><mailto:[EMAIL PROTECTED]> >For additional commands, e-mail: ><mailto:[EMAIL PROTECTED]> > _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>