Note that there are some explanatory texts on larger screens.

plurals
  1. POHtml optional box selected issue
    text
    copied!<p>I've a html list of select item. There is a value name: <strong>other</strong>, which if selected, I want to show a text input.</p> <p>The following is my code. If the user selects any option except <code>other</code>, the text input should hide. How do I show this text field when the user selects <code>other</code> from the select.</p> <pre><code>&lt;td&gt; Interest &lt;span style="color:#F00;"&gt;*&lt;/span&gt; &lt;/td&gt; &lt;td&gt; &lt;select name="interest" id="travel_arriveVia" onchange="showfield(this.options[this.selectedIndex].value)"&gt; &lt;option value="art" &lt;?php if ($g_interest=="art" ) echo 'selected = "selected"'; ?&gt;&gt;Art&lt;/option&gt; &lt;option value="litteratures" &lt;?php if ($g_interest=="litteratures" ) echo 'selected = "selected"'; ?&gt;&gt;Litteratures&lt;/option&gt; &lt;option value="business" &lt;?php if($g_interest=="business" ) echo 'selected = "selected"'; ?&gt;&gt;Business&lt;/option&gt; &lt;option value="internet" &lt;?php if($g_interest=="internet" ) echo 'selected = "selected"'; ?&gt;&gt;Internet&lt;/option&gt; &lt;option value="other_interest" &lt;?php if($g_interest=="internet" ) echo 'selected = "selected"'; ?&gt;&gt;Other&lt;/option&gt; &lt;/select&gt; &lt;script type="text/javascript"&gt; function showfield(name) { if (name == 'other_interest') document.getElementById('div1').innerHTML = '&lt;input type="text" name="other_interest" class="trother" /&gt;'; else document.getElementById('div1').innerHTML = ''; } &lt;/script&gt; &lt;div id="div1"&gt;&lt;/div&gt; &lt;/td&gt; </code></pre> <p>Thanks.</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