<!--1. Insert the script tags in the document.2. Create a dropdown input with class="tobutton"3. The form will now submit a hidden input called "submittedbutton" with the value of the button clicked--><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script><scripttype="text/javascript">varsubmitbutton={};varform={};// find the form and submit button to anchor to$("select.tobutton").each(function(){form=$(this).closest('form');submitbutton=form.find(':submit').first();});// Create the new submit buttons for each item in the dropdown$("select.tobutton > option").each(function(){newbutton=$("<input type='submit' />");newbutton.val($(this).text());newbutton.insertAfter(submitbutton);});// Create a hidden input to store which button was pressedform.prepend($("<input name=\"submittedbutton\" type=\"hidden\" id=\"submittedbutton\" value=\"\">"));// Set the hidden input to the value of the button$('input[type="submit"]').click(function(e){$("#submittedbutton").val($(this).val());});// Get rid of the selects we used to populate the form so no one sees them$("select.tobutton").each(function(){$(this).remove();});</script>
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.