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 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool how to implement different behaviours of a form?

    hi all,
    i have a form with two buttons and various text fields. i want to manipulate the field values on pressing any one button among two buttons.that is, if user clicks "button1" then the values are sent to same page(i.e.,PHP_SELF) also if user clicks "button2" then the values are sent to "page2.php". both are submit type buttons which are inside the form(only one form). how to do this?

  • #2
    Regular Coder
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    159
    Thanks
    2
    Thanked 15 Times in 15 Posts
    Use javascript to manipulate the action of the form?


    Code:
    <script language="JavaScript">
    function SubmitForm()
    {
    
    if(document.pressed == 'This Page')
    {
         document.form1.action ="thispage.php";
    }
    else
    if(document.pressed == 'Page 2')
    {
         document.form1.action ="page2.php";
    }
    return true;
    }
    
    </script>
    
    <form name="form1" onSubmit="return SubmitForm();">
    
    <input type="submit" name="WhatToDo" onClick="document.pressed=this.value" VALUE="This Page">
    
    <input type="submit" name="WhatToDo" onClick="document.pressed=this.value" VALUE="Page 2">
    
    </form>


  •  

    Posting Permissions

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