tags:

views:

145

answers:

1

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
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
Fails when value selection changed using arrow keys in FF3.5
rahul
Yes I already have that code..but IE does not fire the change event
It works only when combo loses focus.
rahul
@TM: Then, click event will do it...
Ei Maung
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