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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help!--Function that responds to a click on page with alert

Status
Not open for further replies.

swannpup

Technical User
Jan 17, 2001
1
US
I need to write a function that responds to a click any where on the page by displaying alert() the event name if the user held Shift during the mouse click, or the name of the element that triggered the event if the user held ctrl during the mouse click. I tried to do this, but an alert--the wrong alert pops up whenever someone clicks without holding a key down. This is my script so far:

<!--
<SCRIPT LANGUAGE=&quot;Javascript&quot;>
function documentClick()
{
if ((documentClick.shiftkey))
alert( &quot;You clicked the Shiftkey when you clicked the document with your mouse.&quot; );
}
{
if ((documentClick.ctrlKey))
alert( &quot;You clicked the ctrl key when you clicked the document with your mouse.&quot;);
}
document.onclick=documentClick;
</script>
-->


If you know what I am doing wrong please help me fix it. Thanks in advance for your help!

Linda
 
I am not sure what this means:

if(documentClick.shiftKey)

It is some reference to a property of the function? Is that something related to the event which has occured? I have not come across this before. When I test this code I get no response what-so-ever?

I think you are needing to capture keyPress as well.You can do this using event.modifiers. Unftunately this is NN4+ only! Bummer I know. &quot;Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top