i need to add input to a select option when it is selected. whenever the user selects 'other' an input box is there for the user to enter in data.
html:
<select>
<option>Choose Your Name</option>
<option>Frank</option>
<option>George</option>
<option>Other</option>
</select>
<!-- when other is selected add input
<label>Enter your Name
<input></input>
</label> -->
my jsfiddle: http://jsfiddle.net/rynslmns/CxhGG/1/
Here is a pure javascript version, no jQuery needed:
jsFidle
As stated before, add onChange event, link it to function and there process what should be displayed etc.
You can use jquery
.change()
to bind change event of an element.Try this one:
HTML
Jquery
Try in Fiddle
Updated:
You can also add an input-box dynamically -
HTML
Jquery
Try in Fiddle
See it in action here.
HTML:
jQuery:
Note the
value="other"
attribute on the "Other" option. That's how the script determines if the "Other" option is selected.Hope this helps!