text/string drop-down values cannot be filled


text/string drop-down values cannot be filled



I am wondered why its happening.



Actually, I am using dropdown based textbox selection.



whenever my drop-down option value I am using numbers then textbox filled properly based on my drop-down selection.



Although I am using my dropdown value text/string then textbox values cannot be filled when I change my drop-down selection.



I want drop-down option value text/string then textbox value filled.pls, help a lot.



Working Code:-


<select id="sel_depart">
<option value="0">- Select -</option>
<option value="1">too</option>
<option value="2">Stencil</option>
</select>

<input id="sel_user" size="">



Jquery


$("#sel_user").empty();
for (var i = 0; i < len; i++) {
var id1234 = response[i]['id123'];
var name1234 = response[i]['name123'];
$("#sel_user").val(name1234);
}



The same code is not working when i just change my <option value="too">too</option> instead of <option value="1">too</option>


<option value="too">too</option>


<option value="1">too</option>





Cannot understand your problem
– Kiran Shahi
24 mins ago






Setting a value in a dropdown will effect only if the value you are setting is already added in the dropdown as an option.
– elegant-user
24 mins ago




1 Answer
1



listen for the change event on the sel_depart and set the value of the input accordingly :


change


sel_depart


value




$(document).ready(function(){
$('#sel_depart').on('change', function(){
//var value = $(this).val(); // uncomment this line to get the value (0, 1, 2 ... )
var value = $(this).children('option:selected').text();
$('#sel_user').val( value );
});
});


https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
<select id="sel_depart">
<option value="0">- Select -</option>
<option value="1">too</option>
<option value="2">Stencil</option>
</select>

<input id="sel_user" size="">






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages