I am calling a JavaScript function when an option is selected in a select element like so:
<select id="select-thingy" onchange="foo(event, this); false;"> <option value="bar">asdf</option> ... </select>
The function does something like this:
function foo(e, elem) { var thingummy = elem.options[elem.selectedIndex].value; alert(e.ctrlKey); // for testing only if (e.ctrlKey) { // do something } else { // do something else } }
According to the alert, e.ctrlKey
is undefined – I thought this was supposed to return either true or false? What am I missing here?
Advertisement
Answer
As per the standard, the attribute ctrlKey
is only available on MouseEvent
s (like click
, mouseover
, etc.) but not HTMLEvent
s.