Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6963699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:49:40+00:00 2026-05-27T15:49:40+00:00

If I have a form which have 2 buttons , and when I click

  • 0

If I have a form which have 2 buttons , and when I click Button1 then it will be action="submit1.php" , if Button2 then action="submit2.php".

I tried this:

  <script language="javascript">

  function Button1()
   {
     document.Form1.action = "submit1.php"   
     document.Form1.target = "iframe1";    
     document.Form1.submit();        

   }

  function Button2()
   {
    document.Form1.action = "submit2.php" ;
    document.Form1.target = "iframe2";    
    document.Form1.submit();       
   }

 </script>

Somewhere in the <body>:

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

And in the form:

  <form name="Form1" id="Form1" method="post">
  <input type="submit" name="Button1" onclick="Button1();">
  <input type="submit" name="Button2" onclick="Button2();">
  </form>

It’s not working , am I make anything wrong?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:49:41+00:00Added an answer on May 27, 2026 at 3:49 pm

    You have two issues

    EITHER

    change the buttons to type=”button”

    OR

    remove the submit from the functions

    Plain JS (using the simpler forms access):

    <script language="javascript">
    function Button(theButton) {
      var theForm = theButton.form;
      if (theButton.name=="Button1") {
        theForm.action = "submit1.php"   
        theForm.target = "iframe1";    
      }
      else {
        theForm.action = "submit2.php"   
        theForm.target = "iframe2";    
      }
    }
    </script>
    
    <form method="post" action="nojsavailable.php">
      <input type="submit" name="Button1" onclick="Button(this);" />
      <input type="submit" name="Button2" onclick="Button(this);" />
    </form>
    

    Unobtrusively (recommended):

    <script language="javascript">
    window.onload=function() {
      var buttons = document.getElementsByName("button");
      for (var i=0;i<buttons.length;i++) {
        buttons[i].onclick=function() {
          var idx = i+1;
          var theForm = this.form;
          theForm.action = "submit"+idx+".php"   
          theForm.target = "iframe"+idx;    
        }
      }
    }
    </script>
    
    <form method="post" action="nojsavailable.php">
      <input type="submit" name="button" id="button1" />
      <input type="submit" name="button" id="button2" />
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form which I want to submit upon button click which is
I have WPF Form which has many buttons with the same code. Appearance of
I have a form in which several buttons are added at runtime via a
I have a form with a few buttons which execute code when pressed like
I have a web form that has 2 radio buttons, depending on which one
i have a form button in the form,which i need to perform basic action
I have a form where you may press a button which will give you
I have two .php files which show all contacts in a database, then allows
I have a html form, which like this: I have 2 fields, name and
I have a form which as two buttons: cancel and submit Here is an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.