Multiple Submit buttons on a form - Which one pressed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dan Lubbs
    New Member
    • Mar 2011
    • 1

    #1

    Multiple Submit buttons on a form - Which one pressed

    -- When you press one of the submit buttons the SetYesNo onclick function starts first & sets the value of the hidden form variable at the bottom (vReviewButton) .
    --

    Code:
    <script LANGUAGE="JavaScript">
    function SetYesNo(YN)
    {
    theForm.vReviewButton.value = YN;
    }
    </script>
    
    
    -- Next, the onsubmit function is started (after the button's onclick) to show the value of the button
    --
    
    -- After the form's onsubmit is run the action redirects to the next html/asp step
    --
    
    <script LANGUAGE="JavaScript">
    function Chk()
    {
       if (theForm.vReviewButton.value == "Yes")
       {
       alert("You pressed Yes");
       }
    
       if (theForm.vReviewButton.value == "No")
       {
       alert("You pressed No");
       }
    }
    </script>
    
    <form method="post" onsubmit="return Chk(this)" name ="theForm">
    <input type="submit" value="Yes" name="vReviewButtonYes" 
    onclick="SetYesNo('Yes')"/>
    
    <input type="submit" value="No" name="vReviewButtonNo" 
    onclick="SetYesNo('No')"/>
    
    <input type="hidden" name="vReviewButton" value=""/>
    </form>
    _______________ ______________

    Is it conveluted - YES - but it was driving me crazy & I found a simple solution (I like simple) that works with javascript
    Last edited by Dormilich; Mar 12 '11, 06:24 AM. Reason: please use [CODE] [/CODE] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    I doubt the form will submit …

    Comment

    Working...