Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

alert box does not disappear

Status
Not open for further replies.

lsyhu

Programmer
Apr 27, 2002
12
US
Hi,

I am maintaing an application which uses perl as the web language. On Netscape 4.7 (not IE) if the Date text field is entered incorrectly, the alert box never disappears when you click OK. The source html code is below. How to solve this problem? Thanks a lot

Lisa

------------------
<head>

<html>

<script language=&quot;javascript&quot;>
function validDate( dateStr )
{
var datePattern = /[0-9]{1,2}-[a-zA-Z]{3}-[0-9]{4}/;

if ( dateStr != &quot;&quot; ){
if (!datePattern.test(dateStr))
alert(&quot;Invalid date format. Format required is DD-MON-YYYY.&quot;);
}
}
</script>
</head>

<body>
<table>
<form name=form1 action=a.html>
<TR>
<td class=&quot;reqFont&quot; align=&quot;left&quot; width=&quot;100&quot; height=&quot;30&quot;>
<b>Requested Completion Date</b>
</td>
<td class=&quot;reqFont&quot; height=&quot;30&quot; align=&quot;left&quot; width=&quot;100&quot;>
<input type=&quot;text&quot; name=&quot;DATE&quot; value=&quot;&quot; onBlur=&quot;validDate(this.value)&quot;>
<a href=&quot;#&quot; onClick=&quot;window.dateField=document.reqTabForm.DATE;calendar=window.open('../html/calendarWin.htm', 'cal', 'width=200,height=250,top=' + dialogHeight + ',left=' + dialogWidth); return false&quot; tabindex=&quot;-1&quot;><img src=&quot;../images/calendarbutton.gif&quot; border=0 width=&quot;20&quot; height=&quot;20&quot; alt=&quot;Date format: DD-MON-YYYY
(example: 01-JAN-2002)&quot;>
</a>
</td>
</TR>

<TR>
<td class=&quot;reqFont&quot; align=&quot;left&quot; width=&quot;100&quot; height=&quot;30&quot;>
<b>hh</b>
</td>
<td width=&quot;30&quot; height=&quot;30&quot;>
hh <input type=&quot;text&quot; name=&quot;TO_TEST_TITLE&quot; size=&quot;46&quot; maxlength=&quot;46&quot; value=&quot;&quot;>
</td>
</TR>

</form>
</table>
</body>

</html>
-----------------------

 
onBlur=&quot;validDate(this.value)&quot;

This calls validDate() where the alert() is every time the alert is not focuse on. It goes around in circles for that reason.

Try using a function that checks all your field when you try to submit.

<form onsubmit=&quot;checkForm()&quot;>

then whenever you try to submit it would run checkForm(). Do all your checks inside that function and if you find an error alert() the message, then focus() on the element and return false so the form is not submitted. If checkForm() finds no errors return true and your form will submit.

I hope this helps. Gary Haran
 
I copied and pasted your code into an HTML document and tested it in Netscape 4.76, and it worked fine, only one alert.

Maybe add:

if ( dateStr != &quot;&quot; ){
if (!datePattern.test(dateStr)){
alert(&quot;Invalid date format. Format required is DD-MON-YYYY.&quot;);
document.form1.DATE.focus();
}
}

to put the focus back in the place where the error is.
 
Thanks for your reply. The HTML codes work well, but the code is generated by Perl, and it does not work in that way.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top