Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    165
    Thanks
    38
    Thanked 2 Times in 2 Posts

    Need help to create 2 submit button to execute 2 different scripts

    Hi Frnds,

    I have form and it needs 1 "save" button & 1 "close" button which need to link to 2 different scripts, Save.php & close.php.

    Please help me complete these requirement.


    Regards,
    Nani
    Last edited by nani_nisha06; 02-04-2013 at 12:51 PM.

  • #2
    Regular Coder
    Join Date
    Mar 2008
    Location
    London
    Posts
    152
    Thanks
    4
    Thanked 42 Times in 42 Posts
    html will look something like this (calling two different JavaScript functions on two buttons) -
    Code:
    <form name="MyForm"> 
    .....
    .....
    <input type="button" value="Save" onclick="return saveData()">
    <input type="button" value="Close" onclick="return closePage()">
    .....
    .....
    </form>
    Then in the JavaScript function, set the action attribute of form as -
    Code:
    function saveData() {
      // logic for validating form data etc.
      // if all successful
      {
        MyForm.action = "save.php";
        MyForm.method = "POST";
        MyForm.submit();
        return true;
      }
      return false;
    }
    
    function closePage() {
      MyForm.action = "close.php";
      MyForm.method = "POST";
      MyForm.submit();
      return true;
    }
    Hope it helps you out...

    Regards,
    Niral Soni

  • Users who have thanked niralsoni for this post:

    nani_nisha06 (02-04-2013)

  • #3
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    165
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Then in the JavaScript function, set the action attribute of form as -
    Code:
    function saveData() {
      // logic for validating form data etc.
      // if all successful
      {
        MyForm.action = "save.php";
        MyForm.method = "POST";
        MyForm.submit();
        return true;
      }
      return false;
    }
    
    function closePage() {
      MyForm.action = "close.php";
      MyForm.method = "POST";
      MyForm.submit();
      return true;
    }

    Hope it helps you out...

    Regards,
    Niral Soni[/QUOTE]

    I need some clarification on the above code

    can I use as below in the above function

    PHP Code:
    MyForm.action = "save.php?xyz=<?echo $xyz;?>";

  • #4
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    165
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by niralsoni View Post
    html will look something like this (calling two different JavaScript functions on two buttons) -
    Code:
    <form name="MyForm"> 
    .....
    .....
    <input type="button" value="Save" onclick="return saveData()">
    <input type="button" value="Close" onclick="return closePage()">
    .....
    .....
    </form>
    Then in the JavaScript function, set the action attribute of form as -
    Code:
    function saveData() {
      // logic for validating form data etc.
      // if all successful
      {
        MyForm.action = "save.php";
        MyForm.method = "POST";
        MyForm.submit();
        return true;
      }
      return false;
    }
    
    function closePage() {
      MyForm.action = "close.php";
      MyForm.method = "POST";
      MyForm.submit();
      return true;
    }
    Hope it helps you out...

    Regards,
    Niral Soni
    This one worked......


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •