How can I set the selected value of a dropdown using javascript?
This is my HTML:
<select id="strPlan" name="strPlan" class="formInput">
<option value="0">Select a Plan</option>
</select>
I am using javascript to add values. Can anyone tell me how to call a function to select a value?
So, you want to change the value of the option that is currently selected. Is that correct?
And call it like this:
Demo
In case you meant that you want to select an option based on its value, use this:
Declare this function:
Now call that to set the option by value, like this, with the first parameter being the select element and the second being the value:
Demo