shinjuo
shinjuo

Reputation: 21012

Two actions with one form

I am trying to have a form submit to two different pages with one button press. Currently I am trying to submit the pages to two hidden iframes, but the second action doesnt seem to be working when I submit my form. Here is the edited version of what I am trying

<script language="javascript">
<!--
function OnButton1()
{
    document.Form1.action = "test1.php"    // First target
    document.Form1.target = "iframe1";    // Open in a iframe
    document.Form1.submit();        // Submit the page
    document.Form1.action = "test2.php"    // Second target
    document.Form1.target = "iframe2";    // Open in a iframe
    document.Form1.submit();        // Submit the page


}
-->
</script>


Submit Button
<input name="submit" src="test.png" type="image" id="submit" style="width: 238px; height: 92px; margin-top: 5px;" value="Submit" onclick="OnButton1();" />

iframes

<div style="visibility:hidden">
<iframe NAME="iframe1" WIDTH="40" HEIGHT="40"></iframe>
<iframe NAME="iframe2" WIDTH="40" HEIGHT="40"></iframe>
</div>

Upvotes: 0

Views: 267

Answers (4)

SkaJess
SkaJess

Reputation: 934

You cannot submit 2 forms in the same time. I think that you must change your strategy to manage your case.

Pascal

Upvotes: 1

siddharth gupta
siddharth gupta

Reputation: 305

try this once

In javascript add this function

   submitForms = function()
   {
          document.getElementById("formID1").submit();
          document.getElementById("formID2").submit();
   }

now single form has to get 2 id's here is it

    <form id="formID1" target="iframe1">
    </form><iframe name="iframe1" style="display:none"></iframe>
    <form id="formID2" target="iframe2">
    </form><iframe name="iframe1" style="display:none"></iframe>
     <input type="button" value="Click Me!" onclick="submitForms()" />

Check this URL For DEMO http://plungjan.name/test/duosubmit.html

Upvotes: 0

Ankur
Ankur

Reputation: 791

Since your form is submitted, your script does not executes further. Try submitting the form to second action on load of first iframe.

window.iframe2.onload = function(){
    document.Form1.action = "test2.php"    // Second target
    document.Form1.target = "iframe2";    // Open in a iframe
    document.Form1.submit();  
}

You'll need to have some kind of condition to prevent the form on load of window for the very first time.

Upvotes: 0

Sanoob
Sanoob

Reputation: 2474

Change your input type to button.I think this will fix your problem. Instead of using iframe you can go with ajax. If you are familiar jQuery this would help you.

Upvotes: 0

Related Questions