Question

I can't quite get my Javascript to select this item in a list. There are two identifiers that I must use to select an item in a list, using Javascript in an Applescript. I can't feasibly script the GUI, so this must be done programatically. Below is my latest effort.

HTML Tag and Value:

<option value="48">48&nbsp;-&nbsp;State</option>

Javascript attempt:

do JavaScript "var elements = document.getElementsByTagName('option');
for (i=0;i<elements.length;i++) {
  if(elements[i].value == '48') {
    elements[i].checked = true;
  }
}" in doc
Was it helpful?

Solution

selected is the attribute for option.

elements[i].selected = true;

http://jsfiddle.net/JU63h/6/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top