I have a html combo/select. When the user selects a element, I want to populate textboxcontrol from it. How to do it.
+3
A:
HTML:
<select id="combobox">
<option value="">Pick one</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<input id="textbox" type="text" />
Javascript (assumes jQuery):
$('#combobox').change( function(){
$('#textbox').val( $(this).val() );
}).click( function(){
$('#textbox').val( $(this).val() );
});
cpharmston
2009-09-07 05:18:41
I don't think IE will fire the change event until after the select loses focus, so this might not behave exactly as he is expecting for IE.
TM
2009-09-07 05:20:43
Fails when value selection changed using arrow keys in FF3.5
rahul
2009-09-07 05:26:51
Yes I already have that code..but IE does not fire the change event
2009-09-07 05:27:20
It works only when combo loses focus.
rahul
2009-09-07 05:27:26
@TM: Then, click event will do it...
Ei Maung
2009-09-07 05:29:03
Edited to include click event.Motim: If you have already tried to tackle a problem and have encountered bugs, then please mention those bugs. http://www.catb.org/~esr/faqs/smart-questions.html
cpharmston
2009-09-07 05:34:06