Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should keep the <code>select</code> element <code>disabled</code> but also add another hidden <code>input</code> with the same name and value.</p> <p>If you reenable your SELECT, you should copy its value to the hidden input in an onchange event and disable (or remove) the hidden input.</p> <p>Here is a demo:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>$('#mainform').submit(function() { $('#formdata_container').show(); $('#formdata').html($(this).serialize()); return false; }); $('#enableselect').click(function() { $('#mainform input[name=animal]') .attr("disabled", true); $('#animal-select') .attr('disabled', false) .attr('name', 'animal'); $('#enableselect').hide(); return false; });</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>#formdata_container { padding: 10px; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt; &lt;div&gt; &lt;form id="mainform"&gt; &lt;select id="animal-select" disabled="true"&gt; &lt;option value="cat" selected&gt;Cat&lt;/option&gt; &lt;option value="dog"&gt;Dog&lt;/option&gt; &lt;option value="hamster"&gt;Hamster&lt;/option&gt; &lt;/select&gt; &lt;input type="hidden" name="animal" value="cat"/&gt; &lt;button id="enableselect"&gt;Enable&lt;/button&gt; &lt;select name="color"&gt; &lt;option value="blue" selected&gt;Blue&lt;/option&gt; &lt;option value="green"&gt;Green&lt;/option&gt; &lt;option value="red"&gt;Red&lt;/option&gt; &lt;/select&gt; &lt;input type="submit"/&gt; &lt;/form&gt; &lt;/div&gt; &lt;div id="formdata_container" style="display:none"&gt; &lt;div&gt;Submitted data:&lt;/div&gt; &lt;div id="formdata"&gt; &lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload