By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,747 Members | 1,352 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,747 IT Pros & Developers. It's quick & easy.

Programmatic Onclick

P: n/a
I need the alternative for the click() method that will work in the
latest FireFox and Netscape browsers. I have found postings like the
one below, but I can't seem to make it work.

http://groups-beta.google.com/group/...ogrammatically

I have a tree menu that I store the levels in a cookie, when the user
returns, I read the level values out of the cookie so the tree is in
its' former state. I need to know how to programmatically click
document.getElementsByTagName('LI')[lev1]

Any help or pointers appreciated. - John

//Returns tree to previous state. Cookie only held for browser
session.
function setTreeVals(){
//checks for TreeVals existence
if(document.cookie.indexOf('TreeVals') > -1){
var levels=getSection('TreeVals');
var lev1=levels.split('|')[0]
var lev2=levels.split('|')[1]
var lev3=levels.split('|')[2]
var lev4=levels.split('|')[3]
//opens tree
if(lev1)
document.getElementsByTagName('LI')[lev1].click();
if(lev2)
document.getElementsByTagName('LI')[lev2].click();
if(lev3)
document.getElementsByTagName('LI')[lev3].click();
if(lev4)
document.getElementsByTagName('LI')[lev4].click();
}
}

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
johkar wrote:
I need the alternative for the click() method that will work in the
click() or onclick()?
latest FireFox and Netscape browsers. I have found postings like the
one below, but I can't seem to make it work.

http://groups-beta.google.com/group/...ogrammatically

Presumably you have set an onclick event on each <li> that
displays the lower levels. So all you want to do is fire the
appropriate event(s).
I have a tree menu that I store the levels in a cookie, when the user
returns, I read the level values out of the cookie so the tree is in
its' former state. I need to know how to programmatically click
document.getElementsByTagName('LI')[lev1]


As Grant suggested in your referenced post, try:

document.getElementsByTagName('LI')[lev1].onclick();

--
Fred
Jul 23 '05 #2

P: n/a

Fred Oz wrote:
johkar wrote:
I need the alternative for the click() method that will work in the


click() or onclick()?
latest FireFox and Netscape browsers. I have found postings like the one below, but I can't seem to make it work.

http://groups-beta.google.com/group/...ogrammatically


Presumably you have set an onclick event on each <li> that
displays the lower levels. So all you want to do is fire the
appropriate event(s).
I have a tree menu that I store the levels in a cookie, when the user returns, I read the level values out of the cookie so the tree is in its' former state. I need to know how to programmatically click
document.getElementsByTagName('LI')[lev1]


As Grant suggested in your referenced post, try:

document.getElementsByTagName('LI')[lev1].onclick();

--
Fred


Let me clarify, the click() method in IE is the same as if you had
clicked on the object with your mouse. I need to do the same thing
with the latest non IE browsers. The other post in my message referred
to using eventListeners and dispatchEvent, but I couldn't seem to make
that work either. I am still confused on how to appraoch.

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.