View Full Version : Resolved Not recognizing onclick event

12-15-2011, 07: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.


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

function ClickFuntion(nodeButtonNum)
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;


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

12-15-2011, 07: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?