Problem calling function using dispatchEvent to click on links

J

johkar

In Firefox when I simulate a click on a link, the link reference ('a')
is returned to function showFK(a) as 'undefined'. Since the link
reference is undefined style changes cannot be executed. Ideas?

Here is the link:
<a href="someURL.htm" onclick="return showFK(this)">Auto</a>

//The link calls this function:
function showFK(a) {
a.style.display="none";
a.parentNode.children["fk"].style.display="inline";
return false;
}

//This code is executed on page load; it loops through all the links
with text of 'Auto' and clicks them:

var lnk, lnkLgth, sel, selLgth, eventObj;
lnk=document.getElementsByTagName('a');
lnkLgth=lnk.length;

for(i=0;i<lnkLgth;i++){
if(lnk.firstChild.nodeValue=='Auto'){
if(document.createEvent){
eventObj=document.createEvent('MouseEvent');
eventObj.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0,
false, false, false, false, 0, null);
lnk.dispatchEvent(eventObj);
}
else {
lnk.click();
}
}
}
sel=document.getElementsByTagName('select');
selLgth=sel.length;
for(i=0;i<selLgth;i++){
sel.selectedIndex=sel.options.length-1;
}
 
M

Martin Honnen

johkar said:
In Firefox when I simulate a click on a link, the link reference ('a')
is returned to function showFK(a) as 'undefined'. Since the link
reference is undefined style changes cannot be executed. Ideas?

Here is the link:
<a href="someURL.htm" onclick="return showFK(this)">Auto</a>

//The link calls this function:
function showFK(a) {
a.style.display="none";
a.parentNode.children["fk"].style.display="inline";
^^^^^^^^
The W3C DOM does not define a children property. There is a childNodes
property however. So unless you use a beta of Firefox 3.5 where children
has been added (https://developer.mozilla.org/En/DOM/Element.children) I
don't think the above will work with Mozilla.
 
J

johkar

johkar said:
In Firefox when I simulate a click on a link, the link reference ('a')
is returned to function showFK(a)  as 'undefined'.  Since the link
reference is undefined style changes cannot be executed.  Ideas?
Here is the link:
<a href="someURL.htm" onclick="return showFK(this)">Auto</a>
//The link calls this function:
function showFK(a) {
    a.style.display="none";
    a.parentNode.children["fk"].style.display="inline";

                    ^^^^^^^^
The W3C DOM does not define a children property. There is a childNodes
property however. So unless you use a beta of Firefox 3.5 where children
has been added (https://developer.mozilla.org/En/DOM/Element.children) I
don't think the above will work with Mozilla.

Ok thanks. I was thinking I put an an alert at the beginning of
function showFK and it was coming in as undefined...obviously I did
not or I might have figured that out myself. FYI, this is a vendor
application where I don't have access to change this page's code. On
the page are a about 20 links which when clicked reveal a select list
which needs to be set to another value (always to the same value in
our case). I was just making a bookmarklet to take out the annoyance
of having to do that process manually. We use IE at work so the
bookmarklet works for that but I was just thinking I would make it
cross browser...and not thinking too much about the app's functions.

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,102
Messages
2,570,645
Members
47,245
Latest member
ShannonEat

Latest Threads

Top