Detecting pressed key during onChange Event

I am wondering if it's possible in Firefox (I know IE can do this) to detect what key a user is holding down during an onChange event on a select tag.

If so, how?
LVL 1
chadsaunAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZvonkoSystems architectCommented:
Show your IE version and we can extend it for FF.
0
chadsaunAuthor Commented:
Here is my code...

function whatever2(oEvent) {
      alert(oEvent.ctrlKey);
      if(oEvent.ctrlKey) {
            alert("ctrlKey!");
      }
      alert(oEvent.keyCode);
}

for this piece of HTML...

<select id="selStuff" onChange="whatever2(event)">
      <option value="one">One</option>
      <option value="two">Two</option>
      <option value="three">Three</option>
      <option value="four">Four</option>
</select>

In IE, this will alert "true", then "ctrlKey!", and then 0

In Firefox, this will alert "undefined", "undefined"
0
ZvonkoSystems architectCommented:
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

chadsaunAuthor Commented:
Thanks, I've already visited that site though before I came here and couldn't come up with an alternative....yet.
0
ZvonkoSystems architectCommented:
It seams in onChange event handler are NO keystrokes attributes available.
So far this is the closest approach that I could get:

<html>
<head>
<title>Zvonko &#42;</title>
<script>
var mask = 0;
var keyCode = 0;
function whatever2(oEvent) {
  var ctrlKey = (oEvent.ctrlKey)?oEvent.ctrlKey:mask&2;
    //alert(ctrlKey);
    if(ctrlKey) {
      alert("ctrlKey!");
    }
    //alert(keyCode);
}
function storeMask(e){
  mask = (e.altKey)?1:0;
  mask += (e.ctrlKey)?2:0;
  mask += (e.shiftKey)?4:-0;
  keyCode = (e.which)?e.which:e.keyCode;
}

</script>
<body>
<form>
<select id="selStuff" onChange="whatever2(event)" onKeyDown="storeMask(event)" onKeyUp="storeMask(event)">
     <option value="one">One</option>
     <option value="two">Two</option>
     <option value="three">Three</option>
     <option value="four">Four</option>
</select>
</form>
</body>
</html>

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chadsaunAuthor Commented:
That's a good try Zvonko. Not quite what I'm looking for though. I'd like to have to require them to be holding down the ctrl Key when they change the option.

This might not be possible since IE does give you the key properties even when it's not a "key" event like onChange. I know Firefox doesn't give you those attributes but I was looking for an alternative that worked the same.

I don't know if this is possible, but can you put an event listener on another event listener?
0
ZvonkoSystems architectCommented:
You can. But then you get only the attributes and properties of the current event handler.
That does say: you can call in onChange event handler the onKeyPress event handler, but you get only onchange attributes.


0
chadsaunAuthor Commented:
Oh I see. Okay.
0
chadsaunAuthor Commented:
I found that it wasn't possible in Firefox. Only IE since the keystrokes attributes are only available in IE. Thanks for the help Zvonko.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.