Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select an option of select box using the value

I have a dropdown box and I want to select the option based on value. Somehow I am getting handle to value say 3. Now I want to manually select the option which has got value 3.

I have tried something like this

selectBoxElement.options[selectedValues].selected = true;

where selectedValue = 3, but it is not working.

like image 615
Hussy Avatar asked Jan 26 '26 16:01

Hussy


1 Answers

If using jquery (as per your tag), you can do:

$(document).ready(function() {
  $("#yourSelectId option[value='3']").attr("selected", "selected");
});
like image 128
Sudhir Bastakoti Avatar answered Jan 29 '26 04:01

Sudhir Bastakoti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!