multiple submit buttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aashishn86
    New Member
    • Mar 2009
    • 51

    multiple submit buttons

    hi !
    how can i use multiple submit buttons in the same form

    i want to pass form values to different pages depending on which of the two submit button is clicked...
    thank's
  • aashishn86
    New Member
    • Mar 2009
    • 51

    #2
    well i achieved that by using this code i found :

    Code:
    <SCRIPT language="JavaScript">
    function OnSubmitForm()
    {
      if(document.pressed == 'Insert')
      {
       document.myform.action ="insert.html";
      }
      else
      if(document.pressed == 'Update')
      {
        document.myform.action ="update.html";
      }
      return true;
    }
    </SCRIPT>
    
    
    <FORM name="myform" onSubmit="return OnSubmitForm();">
    
    <INPUT TYPE="SUBMIT" name="Operation" onClick="document.pressed=this.value" VALUE="Insert">
    
    <INPUT TYPE="SUBMIT" name="Operation" onClick="document.pressed=this.value" VALUE="Update">
    
    </FORM>
    now the problem is i need to call the validate function as well OnClick
    how do i get around this
    Last edited by acoder; Mar 31 '09, 07:33 AM. Reason: Added [code] tags- please use them

    Comment

    • jhardman
      Recognized Expert Specialist
      • Jan 2007
      • 3405

      #3
      Code:
      <INPUT TYPE="SUBMIT" name="Operation" onClick="validate();document.pressed=this.value" VALUE="Update">
      You can also put all of that functionality within the validate function. This is really more of a javascript question, if you are going to keep the thread going, we should move it to that forum now.

      Jared

      Comment

      • aashishn86
        New Member
        • Mar 2009
        • 51

        #4
        well i tried that..........i t didn't work...
        yups, please move it....
        thank's...

        Comment

        • aashishn86
          New Member
          • Mar 2009
          • 51

          #5
          Code:
          onsubmit="return (onsubmit() && validate(this));"
          i used this for that..........

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            You should avoid using reserved words, e.g. onsubmit for function names. Some browsers may start complaining. You could also call the onsubmitform function within validate(). There's also no need to return from the function because it always returns true.

            Comment

            • aashishn86
              New Member
              • Mar 2009
              • 51

              #7
              hi
              writing onsubmit within validate didn't work for me... don't know why..
              other points noted...
              thank's..

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                In validate(), just before return true at the end, just add:
                Code:
                OnSubmitForm();
                return true;
                then your onsubmit event would be simply:
                Code:
                <form ... onsubmit="return validate(this);">
                (you could always avoid this too and use unobtrusive JavaScript, of course).

                Comment

                Working...