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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form submitssion/cancelling problem

Status
Not open for further replies.

michael3

Programmer
Aug 8, 2001
26
US
Hi,

I have a html page which accepts two inputs (number) from user, and calls a Javascript function doSubmit(form) to check if the input is valid. If not, pop up a alert window, and cancell the form submission. Then, after the user re-input, it should submit the form. But my program does not do it right. If I remove the line
onClick="document.myform.submit()" away from my js code, it just hang on there.

Can anyone tell why? Am I doing something wrong with the event trigger onSumbit="" or onCleck=""? Thanks.

michael

following are the segments of of html and js code.

--------------- fill.html ----------------------

<HTML>
<HEAD>
<TITLE>Fill History</TITLE>
<SCRIPT LANGUAGE=&quot;JavaScript&quot; SRC=&quot;showfill.js&quot;></SCRIPT>
</HEAD>
<BODY BGCOLOR=&quot;#FFFFE1&quot;>
<TABLE border=&quot;0&quot; width=100% >
<TR bgcolor=darkblue>
<TD><FONT face=&quot;Verdana, Arial, Helvetica&quot;
size=&quot;3&quot; color=white> <strong>Central Fill History for a Given Store Number
and Rx Number</strong></FONT></TD>
</TR>
</TABLE>

<FORM name=&quot;myform&quot; method=&quot;post&quot; action=&quot;/webapp/ToolBox/servlet/walgreens.show
fill.proxy.ShowfillProxy/ShowfillReport&quot; onSubmit=&quot;return doSubmit(myform)&quot;>
<p><font face=&quot;Verdana, Arial, Helvetica&quot; size=&quot;2&quot;><b>
Enter the following information:</b></font></p>
<font color=&quot;#000099&quot;></font>
<pre><strong><font face=&quot;Verdana, Arial, Helvetica&quot;>
Store number:  <input type=&quot;text&quot; name=&quot;storeNbr&quot;>
Rx number:       <input type=&quot;text&quot; name=&quot;rxNbr&quot;>
</font></strong></pre>
<BR><BR>

<table border=&quot;0&quot; width=&quot;75%&quot;>
<tr>
<td width=&quot;30%&quot; height=&quot;15&quot; valign=&quot;bottom&quot;>
<input type=&quot;submit&quot; value=&quot;Submit&quot; onClick=&quot;document.myform.submit()&quot;>
<td width=&quot;30%&quot; height=&quot;15&quot; valign=&quot;bottom&quot;>
<input type=&quot;reset&quot; value=&quot;Clear Form&quot;></td>
</tr>
</table>

<SCRIPT language=&quot;JavaScript&quot;> document.myform.storeNbr.focus(); </SCRIPT>

</FORM>

<br>

<table border=&quot;0&quot; width=&quot;75%&quot;>
<tr><td width=&quot;50%&quot; height=&quot;15&quot; valign=&quot;bottom&quot;>
<font face=&quot;verdana,arial,helvetica&quot; size=&quot;2&quot;><a href=&quot;JavaScript:history.back(1
)&quot;><strong>Back</strong></a></font></td>
<td width=&quot;50%&quot; height=&quot;15&quot; valign=&quot;bottom&quot;>
<a href=&quot;
<font face=&quot;Verdana, Arial, Helvetica&quot;>RxS</font></small></strong></a></td></tr>
</table>

<p> </p>
</BODY>
</HTML>

--------------- showfill.js --------

var theflag = true;

function chkStoreNbr(){
/* Store# can only be numbers */
if (notNumber(document.myform.storeNbr.value) == true)
{
alert (&quot;Please enter only numbers in Store# field&quot;);
document.myform.storeNbr.focus();
theflag = false;
}
}

function chkRxNbr(){
if (notNumber(document.myform.rxNbr.value) == true)
{
alert (&quot;Please enter only numbers in Rx# field&quot;);
document.myform.rxNbr.focus();
theflag = false;
}
}

function doSubmit(myform){
chkRxNbr();
if(!theflag) return theflag;
chkStoreNbr();
if(!theflag) return theflag;

return theflag;

/* document.myform.submit(); */
}
 
I would think that you would want to call your doSubmit function from the onclick of the button that you use to submit the form. Then do your validation within the function and either submit the form (if everything is o.ko) or send the alert message.
 
Thanks, Roblasch, for your response. I used my doSubmit() as

<FORM name=&quot;myform&quot; method=&quot;post&quot; action=&quot;/webapp/ToolBox/servlet/walgreens.show
fill.proxy.ShowfillProxy/ShowfillReport&quot; onSubmit=&quot;return doSubmit(myform)&quot;>

and then put it in

<input type=&quot;submit&quot; value=&quot;Submit&quot; onSubmit=&quot;return doSubmit(myform)&quot;>, ==> popup the alert message, if the user reinput, the Submit does not work, my page just hangs on there.

or in
<input type=&quot;submit&quot; value=&quot;Submit&quot; onClick=&quot;document.myform.submit()&quot;> ==> popup the alert message, then sumbit anyway.

michael


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top