I am trying to submit my button with a form. Im not trying to make my button submit the form. I want to be able to see my button value in the POST variable after the form submits. From my understanding all I need is to give my element a name and value. I should be able to see all the form variables once my form is submitted.
<input name='MC[]' type='text' size='51' placeholder='Enter In Question'>
<br/>
<input name='MC[]' type='button' value='Incorrect'>
<input name='MC[]' id='Options' size='40' placeholder='Enter In Option A'>
I'm new to this site not sure if I'm providing enough information but I simply want to submit this button inside a form and to be able to add the value of my button to a file. For some reason I cant see the button once the form is submitted. Are type button not sent to POST when submitted?
Note, I am able to see my other input elements. The type button one is the only one I cant see.
Barmar :
You can use Javascript that fills in the value of a hidden input from the value of the button that was clicked.\n\nHTML:\n\n<input type=\"hidden\" name=\"answer\" id=\"answer\">\n\n\nJS:\n\ndocument.querySelectorAll(\"input[name='MC[]']\").forEach(function(el) {\n el.addEventListener(\"click\", function() {\n document.getElementById(\"answer\").value = el.value;\n }\n}\n\n\nThen you'll be able to get the button's value in $_POST['answer'].",
2017-12-28T20:40:13