Programmatic Onclick

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • johkar

    Programmatic Onclick

    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.



    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 programmaticall y click
    document.getEle mentsByTagName( '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.coo kie.indexOf('Tr eeVals') > -1){
    var levels=getSecti on('TreeVals');
    var lev1=levels.spl it('|')[0]
    var lev2=levels.spl it('|')[1]
    var lev3=levels.spl it('|')[2]
    var lev4=levels.spl it('|')[3]
    //opens tree
    if(lev1)
    document.getEle mentsByTagName( 'LI')[lev1].click();
    if(lev2)
    document.getEle mentsByTagName( 'LI')[lev2].click();
    if(lev3)
    document.getEle mentsByTagName( 'LI')[lev3].click();
    if(lev4)
    document.getEle mentsByTagName( 'LI')[lev4].click();
    }
    }

  • Fred Oz

    #2
    Re: Programmatic Onclick

    johkar wrote:[color=blue]
    > I need the alternative for the click() method that will work in the[/color]

    click() or onclick()?
    [color=blue]
    > 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
    >[/color]

    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).
    [color=blue]
    > 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 programmaticall y click
    > document.getEle mentsByTagName( 'LI')[lev1][/color]

    As Grant suggested in your referenced post, try:

    document.getEle mentsByTagName( 'LI')[lev1].onclick();

    --
    Fred

    Comment

    • johkar

      #3
      Re: Programmatic Onclick


      Fred Oz wrote:[color=blue]
      > johkar wrote:[color=green]
      > > I need the alternative for the click() method that will work in the[/color]
      >
      > click() or onclick()?
      >[color=green]
      > > latest FireFox and Netscape browsers. I have found postings like[/color][/color]
      the[color=blue][color=green]
      > > one below, but I can't seem to make it work.
      > >
      > >[/color][/color]
      http://groups-beta.google.com/group/...ogrammatically[color=blue][color=green]
      > >[/color]
      >
      > 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).
      >[color=green]
      > > I have a tree menu that I store the levels in a cookie, when the[/color][/color]
      user[color=blue][color=green]
      > > returns, I read the level values out of the cookie so the tree is[/color][/color]
      in[color=blue][color=green]
      > > its' former state. I need to know how to programmaticall y click
      > > document.getEle mentsByTagName( 'LI')[lev1][/color]
      >
      > As Grant suggested in your referenced post, try:
      >
      > document.getEle mentsByTagName( 'LI')[lev1].onclick();
      >
      > --
      > Fred[/color]

      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.

      Comment

      Working...