Javascript ile html deki selected option index seçimi yapmak

Paylaş.

 

 

<select name=”country” id=”country”>
<option value=”AF”>Afghanistan</option>
<option value=”AL”>Albania</option>

<option value=”ID”>Indonesia</option>

<option value=”ZW”>Zimbabwe</option>
</select>
<script>

function sec(i){
alert(i);
var country = document.getElementById(“country”);
country.options[i].setAttribute(“selected”, “selected”);
}

</script>

<a href=”javascript:void(0);” onclick=”sec(3);” >sec</a>

 

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: -1 (from 1 vote)