I am trying to change the value a select box when a certain option is chosen. I have searched for ways to do this but nothing that I have found works.
This is what I have:
(function () {
var pdc
$("#dclist").focus(function(){
pdc = this.value;
}).change(function () {
var ndc = this.value;
if (ndc === "Select") {
$("#dclist").val(pdc);
} else {
//something else
}
}
});
})();
Here is the select box:
<select id="dclist">
<option value="Select">Please select</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
Can anyone help?
Thanks Ryan
-snip-
Edit: Jason P has the correct answer. It was just a syntax error. If Jason P posts an answer I'll delete this one.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.