Use Variable Value To Get Value Stored In Other Variable
I am trying to simplify some of the bookmarklets that I have created over the past few days and make them easier for people to use. One of my bookmarklets changes the selected opt
Solution 1:
You could iterate over each of the options in the select element and set the value if "name" element matches with the supplied value, like so:
function setSelect(name) {
var selectEl = document.getElementById("selectElementName");
for (var i = 0; i < selectEl.options.length; i++) {
if (selectEl.options[i].name == name) {
selectEl.selectedIndex = i;
break;
}
}
}
Post a Comment for "Use Variable Value To Get Value Stored In Other Variable"