i trying set selected option of drop down current page on. reason, unknown me it's not working.
<script> var temp = '<?php echo $country;?>'; var forma = document.getelementbyid('forma'); for(var i, j = 0; = forma.options[j]; j++) { if(i.value == temp) { forma.selectedindex = j; break; } } </script> <select name="forma" onchange="location = this.options[this.selectedindex].value;"> <option value="aw">aruba</option> <option value="bh">bahrain</option> <option value="bj">benin</option> <option value="bo">bolivia</option> etc..
the expected result is, when $country = "aw" should say; "aruba".
any appreciated.
why not set value of select
input value of $country
try this:
var temp = 'aw'; $('select[name="forma"]').val(temp);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <select name="forma"> <option value="aw">aruba</option> <option value="bh">bahrain</option> <option value="bj">benin</option> <option value="bo">bolivia</option> </select>
Comments
Post a Comment