Results 1 to 1 of 1

Thread: I am a bit confused, my question is in regards to javascript event

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    5

    I am a bit confused, my question is in regards to javascript event

    Hi,

    I've got a question in my assignment that is

    Write a function that responds to a click anywhere on the page by displaying an alert dialog. Display the event name if the user held Shift during the mouse click. Display the element name that triggered the event if the user held Ctrl during the mouse click.
    I've already completed it i believe, but a bit confused on event name. Could anybody please tell me which one is correct, is it event or event type or something else?

    PHP Code:
    <html>
    <
    head>

    <
    script type="text/javascript">
    function 
    handleClickEvent(event)
    {
        if(
    event.ctrlKey)
        {
            
    //alert(event.clientX+','+event.clientY);
            
    event || window.event;
            var 
    obj e.target || e.srcElement;
            
    alert("Element name where mouse click occured: " obj.nodeName);        
        }
        else if (
    event.shiftKey)
        {
            
    alert("Event name just occured: " event);
            
    alert("Event name just occured: " event.type);
        }
        else
        {
            
    alert("click event occured")
        }    
    }
    </
    script>

    </
    head>
    <
    body onclick="handleClickEvent(event)">
    <
    form>
            <
    input type="text" name="name" />
            <
    input type="password" name="password" />
    </
    form>
    </
    body>
    </
    html
    Last edited by Sahil; Sep 27th, 2007 at 04:05 AM. Reason: added html part too

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width