Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to detect if shift key is pressed when clicking on a link

Navigation

How to detect if shift key is pressed when clicking on a link

by  bustell  Posted    (Edited  )
Here is a little something that I have used to detect if the shift key is pressed while a user is clicking on a link.

I used it for resorting a table by invoking the resort function through the onclick event of <a> tag like this:

onclick="resort("fieldName","DESC");return false;"

Here is the code:

<body onKeyDown="aKeyDown();" onKeyUp="aKeyUp();">
<Script language="javascript">
var shiftPressed;
shiftPressed = false;

function aKeyDown(e) {
e=window.event;
if (e.keyCode==16) {shiftPressed=true;}
}

function aKeyUp(e) {
e=window.event;
if (e.keyCode==16) {shiftPressed=false;}
}

function resort(fieldName, direction) {
if (shiftPressed) {
//Do this if shift is pressed
}
else {
//Do this if shift is not pressed
}

document.forms.viewInfo.submit();
}

</script>
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top