Jump to content

Drop down list onclick


MDanz

Recommended Posts

Need help doing this.  On a drop down list, onclick of an option an input textfield appears.

e.g.

 

echo "<select>
  <option>What is your opinion on</option>

</select>";

echo "<div id='pop'><input type='hidden' id='opinion' size='20' name='opinion' value='Type Keyword Here' /></div>";

 

i want it to be hidden and then appear onclick of the option in the dropdown list... How do i do this?

 

Link to comment
https://forums.phpfreaks.com/topic/206008-drop-down-list-onclick/
Share on other sites

Suppose you got a select element:

<select onchange="optionChanged(this);">
  <option value="1">Option 1</option>
  <option value="2">Option 2</option>
  <option value="3">Option 3</option>
  <option value="0">Other</option>
</select>

 

And a input box:

<input type="text" id="txtBox" size="30" style="display: none;" />

 

Now, put these codes in your header:

<script language="JavaScript" type="text/javascript">
function optionChanged(ele) {
  var val = ele.options[ele.options.selectedIndex].value;
  if (val == 0) {
    document.getElementById("txtBox").style.display = "block";
  }
}
</script>

So when you select Other, the textbox will appear.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.