...

View Full Version : Resolved Not recognizing onclick event



user376
12-15-2011, 06:11 PM
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:


<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
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:


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":
[b]//eval(document.getElementById(gButtonList[gButtonId])).onclick();
var target = eval(document.getElementById(gButtonList[gButtonId]));
target.fireEvent("onclick");
break;
}
}

devnull69
12-15-2011, 06:43 PM
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum