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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.