Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="scripts/jquery.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(function(){ //initially hide the textbox $("#other_reason").hide(); $('#i_n_r_reason').change(function() { if($(this).find('option:selected').val() == "Other"){ $("#other_reason").show(); }else{ $("#other_reason").hide(); } }); $("#other_reason").keyup(function(ev){ var othersOption = $('#i_n_r_reason').find('option:selected'); if(othersOption.val() == "Other"){ ev.preventDefault(); //change the selected drop down text $(othersOption).html($("#other_reason").val()); } }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;fieldset id="workers_comp_info"&gt; &lt;p&gt; &lt;label for="i_n_r_reason"&gt;Reason why Workers Comp Insurance is not required:&lt;/label&gt; &lt;select name="i_n_r_reason" id="i_n_r_reason"&gt; &lt;option value="No employees"&gt;No employees&lt;/option&gt; &lt;option value="1-2 employees"&gt;1-2 employees&lt;/option&gt; &lt;option value="Other"&gt;Other(Specify reason)&lt;/option&gt; &lt;/select&gt; &lt;input id="other_reason" name="other_reason" type="text" placeholder="Other Reason" /&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>So basically what it does is :</p> <p>When the dropdown's changing, evaluate the value. If it's "Others" then show the textbox, else hide it.</p> <p>For the second part, upon submitting the form, evaluate the value of the selected drop down. If it's "Others", then prevent the form from submitting, instead change the text of the selected drop down list to the value from the text box. </p> <p>I guess the code is pretty explainable. Hope this helps.</p> <p><strong>EDITED</strong></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