By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,946 Members | 1,714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,946 IT Pros & Developers. It's quick & easy.

Multiple Submit buttons on a form - Which one pressed

P: 1
-- 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).
--

Expand|Select|Wrap|Line Numbers
  1. <script LANGUAGE="JavaScript">
  2. function SetYesNo(YN)
  3. {
  4. theForm.vReviewButton.value = YN;
  5. }
  6. </script>
  7.  
  8.  
  9. -- Next, the onsubmit function is started (after the button's onclick) to show the value of the button
  10. --
  11.  
  12. -- After the form's onsubmit is run the action redirects to the next html/asp step
  13. --
  14.  
  15. <script LANGUAGE="JavaScript">
  16. function Chk()
  17. {
  18.    if (theForm.vReviewButton.value == "Yes")
  19.    {
  20.    alert("You pressed Yes");
  21.    }
  22.  
  23.    if (theForm.vReviewButton.value == "No")
  24.    {
  25.    alert("You pressed No");
  26.    }
  27. }
  28. </script>
  29.  
  30. <form method="post" onsubmit="return Chk(this)" name ="theForm">
  31. <input type="submit" value="Yes" name="vReviewButtonYes" 
  32. onclick="SetYesNo('Yes')"/>
  33.  
  34. <input type="submit" value="No" name="vReviewButtonNo" 
  35. onclick="SetYesNo('No')"/>
  36.  
  37. <input type="hidden" name="vReviewButton" value=""/>
  38. </form>
_____________________________

Is it conveluted - YES - but it was driving me crazy & I found a simple solution (I like simple) that works with javascript
Mar 11 '11 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
I doubt the form will submit
Mar 12 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.