I have to create one input text box and select box. In select, option will contains some userId values are user names. User can use both text box and select box to input the data. if he/she select any username then userId should be updated in the text box. And vice-versa if user enters userId in textbox userId should be updated in text box.
First part of functionality is working fine.
I am not getting any solution in jQuery, how to make the particular option id selected.
Second Part
These are dynamically created by select and input-boxes. These will be increased. I need to do for each. How can I do the same functionality for the all using jQuery.
<input type="text" id="demoInput" />
<select id="demoSelect" >
<option id="0">User Name A</option>
<option id="1">User Name B</option>
<option id="3">User Name C</option>
<option id="4">User Name D</option>
<option id="5">User Name E</option>
<option id="6">User Name F</option>
</select>
$('#demoSelect').change(function(){
//alert('event fired');
var id = $(this).children(":selected").attr("id");
//alert('id is ' +id);
$('#demoInput').val(id);
});
$('#demoInput').change(function(){
alert('event fired');
$('#demoSelect').children(":selected").removeAttr("selected");
alert('id is ' +id);
$('#demoInput').val(id);
});
I have created this
JS Fiddle as well.