this.fillSelectBox = function (flowCounterObj)
{
while (this.selectBox.hasChildNodes())
{
this.selectBox.removeChild(this.selectBox.firstChild);
}
var line = 0;
for(line = 0; line < this.lines.length; line++)
{
var newOption = document.createElement('option');
newOption.setAttribute('value','line_' + line);
newOption.innerHTML = 'Line ' + line;
newOption.onclick = function(){flowCounterObj.setCurrentLine(this.index);};
this.selectBox.appendChild(newOption);
}
};
The above code removes all options from the select box and the creates a new option for each line I have in my array.
It adds a event to the onclick.
When I select my options in Chrome they call the setCurrentLine() function. However in IE9 it doesn't.
I have looked at the debugging windows in both IE9 and Chrome and they apply the same stuff.
I have tried using setAttribute('onclick',flowCounter.setCurrentLine('+line+');');
but that doesn't work either in IE9 (does in Chrome);
I have also tried using addEventListener(...);
but that doesn't work in IE9 (does in Chrome).
(On a side note should I actually be using addEventListener for this? Is that the correct way?)
I put the code through JS lint and it says I shouldn't create functions in loops?
Any ideas? Do you think this could actually be a bug?
Matt
EDIT : I tried the following HTML code in IE9:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<select id='lineSelect' size='4'>
<option value='line_1' onclick='alert("whoop");'>Line 1</option>
<option value='line_2' onclick='alert("whoop");'>Line 2</option>
<option value='line_3' onclick='alert("whoop");'>Line 3</option>
<option value='line_4' onclick='alert("whoop");'>Line 4</option>
</select>
</body>
</html>
And that doesn't do anything? Does in chrome/safari/firefox/opera! Also did it with onClick/onChange.
I looked at this msdn page , and it seems that an option
doesn't have an onclick
event. However, it does have a onselect
or onchange
event.
I think using the onclick
or onchange
event of the selectbox itself is the best solution in this case.
Also note that from IE9 onwards, onclick is not working anymore. Is onClick "case sensitive"
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.