javascript - jQuery Change radio button on select box change -
i not jquery , having trouble getting right. need change radio button selected if select value in different select box.
<div class="radio-inline" id="sourcediv" role="group"> <input type="radio" id="sourcebtns1" name="sourcebtn" class="btn btn-lg" value="cn"><label for="sourcebtns1">china</label> <input type="radio" id="sourcebtns2" name="sourcebtn" class="btn btn-lg" value="id" ><label for="sourcebtns2">indonesia</label> <input type="radio" id="sourcebtns3" name="sourcebtn" class="btn btn-lg" value="th" ><label for="sourcebtns3">thailand</label> <input type="radio" id="sourcebtns4" name="sourcebtn" class="btn btn-lg" value="us"><label for="sourcebtns4">united states</label> </div> <div id="priceselect"> <select name="priceselect" id="priceselect" class="form-control"> <option value="ftlw">domestic full truck load</option> <option value="ptlw">domestic partial truck load</option> <option value="ftl" selected>international</option> </select> </div> i trying radio button select #sourcebtns4 when "ftlw" option selected in select box.
this function using. not error, cannot function work. not sure problem is. have tried several different things, none of them work.
any suggestions?
$(document).ready(function() { $('#priceselect').change(function(){ if($(this).val() == 'ftlw' ){ $('#sourcebtns4').prop("checked", true); } }); });
you can't have 2 elements same id. div , select both had id of priceselect. it's select care about.
$(document).ready(function() { $('#priceselect').change(function(){ console.log($(this).val()); if($(this).val() == 'ftlw' ){ $('#sourcebtns4').prop("checked", true); } }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div> <select name="priceselect" id="priceselect" class="form-control"> <option value="ftlw">domestic full truck load</option> <option value="ptlw">domestic partial truck load</option> <option value="ftl" selected>international</option> </select> </div> <div class="radio-inline" id="sourcediv" role="group"> <input type="radio" id="sourcebtns1" name="sourcebtn" class="btn btn-lg" value="cn"><label for="sourcebtns1">china</label> <input type="radio" id="sourcebtns2" name="sourcebtn" class="btn btn-lg" value="id" ><label for="sourcebtns2">indonesia</label> <input type="radio" id="sourcebtns3" name="sourcebtn" class="btn btn-lg" value="th" ><label for="sourcebtns3">thailand</label> <input type="radio" id="sourcebtns4" name="sourcebtn" class="btn btn-lg" value="us"><label for="sourcebtns4">united states</label> </div>
Comments
Post a Comment