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

Two Form Submissions w/ One Button Click

Status
Not open for further replies.

kedrew

Programmer
Jun 22, 2001
29
US
(I posted this message to the "AOL: Netscape" list yesterday, but didn't get any responses so I'll try here.)

I'm developing an order processing application that sends data between views using a form with the POST method.
We are using a 3rd party for credit card processing and do not receive any feedback, therefore I'm trying to use one button click to start two form submissions.

The starting page (for this issue) contains a list of products and a button for each product. The user is to click the button next to the product they would like to purchase. After clicking the button, two events should happen: (1) a new window should be created with the page to our outside credit card app, and (2) a new page from our own site that displays an order confirmation. The second page needs information from the first, so our order database can be updated.

The problem that is really baffeling me is that the code works fine with MS IE 5.5 and Netscape Navigator 6, but doesn't work in Navigator 4.

It works in 'debug-mode' when I place an (A)
Code:
alert()
before I change the variables, but I really don't want to have a message box pop-up just to get it to work. I've tried to use a (B)for-loop, but when I do, the 3rd party site never opens (or I never see it open).

JavaScript Code
Code:
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function btnOrder (form_id) {
//submit the form per FORM properties
Code:
  document[form_id].submit();
//((A) message box that makes it work
Code:
//  alert('');

//(B) for-loop that eliminates first submit
Code:
//  for (i=0; i<1000; i++) {
//    ;
//  }


//change FORM variables to point to the new page
Code:
  document[form_id].target=&quot;_self&quot;;
  document[form_id].action=&quot;confirmOrder.asp&quot;;
//submit the form to the new destination
Code:
  document[form_id].submit();
}
</SCRIPT>

Form Elements
Code:
<Form Method=POST Action=&quot;[URL unfurl="true"]http://cc.net/input.asp&quot;[/URL] NAME=&quot;PB_1&quot; TARGET=&quot;_blank&quot; onSubmit=&quot;javascript:btnOrder('PB_1');&quot;>

...

<INPUT TYPE=SUBMIT NAME=SubmitPB VALUE=&quot;Buy&quot;>

..

</FORM>

I've also tried to placing
Code:
onClick=&quot;javascript:btnOrder('PB_1');&quot;
in the SUBMIT command, using both TYPE=SUBMIT and TYPE=BUTTON w/o the OnSubmit action of the form, but nothing works in Netscape 4.

Any thoughts/suggestions that someone would like to throw my way would be greatly appreciated, as I'm at my wits end.

Thanks -
 
And the answer is......

JavaScript Code
Code:
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function btnOrder (form_id) {
	
  document.forms[form_id].submit();

  setTimeout(&quot;document.forms[&quot; + form_id + &quot;].target='_self'; document.forms[&quot; + form_id + &quot;].action='processOrder.asp'; document.forms[&quot; + form_id + &quot;].submit();&quot;, 2000);

  return true;
}
</SCRIPT>

Form Elements
Code:
  <Form Method=POST Action=&quot;[URL unfurl="true"]http://cc.net/input.asp&quot;[/URL] NAME=&quot;0&quot; TARGET=&quot;_blank&quot;>

...

<INPUT TYPE=BUTTON NAME=SubmitPB VALUE=&quot;Buy&quot; onClick=&quot;javascript:btnOrder('0');&quot;>

...

</FORM>

One of the difference is that the form name was changed from PB_x, where x is a counter starting at 1, to solely x, starting at 0. This, in return corresponds to the array element for the document form element.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top