Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Not recognizing onclick event

    I'm having an issue where a programmatic click event is not behaving the same way the cursor click event is. A cursor click returns the correct object from GetObject(). The programmatic click triggered by a USB device is returning undefined from GetObject(). How can this be resolved?


    Edit: It appears that it does not recognize eval(document.getElementById(gButtonList[gButtonId])).onclick(); as an event. Why is this? How can I get it to recognize it?

    Edit2: Resolved it myself. See green text below.

    TestPage.htm:
    Code:
    <script language="JavaScript" src="../bin/USBHelperFile.js"></script>
    <script language="JavaScript" type="text/JavaScript">
    
    function BuildButtons()
    {
        for (var i = 0; i < testArray.length; i++)
        {
            // Create Div [Buttons created programmatically]
            var divNode = document.createElement('div');
            divNode.id = 'div' + i;
            divNode.onclick= ClickFunction;
            etc...
        }
    }
    
    function ClickFuntion(nodeButtonNum)
    {
        alert(GetObject()); 
        Returns the index for a cursor click. Returns undefined for
        the programmatic click triggered by the USB device
    }
    
    
    function GetObject()
    {
        var node = event.srcElement;
        return node;
    }
    </script>

    USBHelperFile.js:
    Code:
    This JS file works with a USB hardware device that can navigate
    through divs and click them when they have focus.
    
    function HelperFunction(keyCommand)
    {
        switch (keyCommand)
        {
            case: "click":
                //eval(document.getElementById(gButtonList[gButtonId])).onclick();
                var target = eval(document.getElementById(gButtonList[gButtonId]));
                target.fireEvent("onclick");
                break;
        }
    }
    Last edited by user376; 12-15-2011 at 06:48 PM.

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    If you programmatically click on an element there is no event. There is just the normal program flow. And in that case you EXACTLY know which is the srcElement anyway because you used it to call the onclick handler. So why would you need to retrieve it again?


  •  

    Posting Permissions

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