SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: onclick tag

  1. #1
    SitePoint Member
    Join Date
    Feb 2004
    Location
    Norway
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onclick tag

    Hi,

    I am trying to learn Javascript DHTML and I am playing with "Switch Menu", which I found at http://www.dynamicdrive.com/dynamici...switchmenu.htm. It's really nice, but I do not like that it closes (i.e. hides the subitems) as soon as I select one of them (subitems).

    The code looks like this:
    <div class="menutitle" onclick="SwitchMenu('sub4')">Cool Links</div>
    <span class="submenu" id="sub4">
    - <a href="http://www.javascriptkit.com">JavaScript Kit</a><br>
    - <a href="http://www.freewarejava.com">Freewarejava</a><br>
    - <a href="http://www.cooltext.com">Cool Text</a><br>
    - <a href="http://www.google.com">Google.com</a>
    </span>

    and I think I understand how it works. But is there a way to prevent SwitchMenu('sub4') getting called when the visitor click one of the subitems?

    Best regards

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...it closes (i.e. hides the subitems) as soon as I select one of them (subitems).
    I don't see that effect. What browser are you using?

  3. #3
    SitePoint Member
    Join Date
    Feb 2004
    Location
    Norway
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MikeFoster
    I don't see that effect. What browser are you using?
    Opera 7.52 (Linux), Mozilla 1.6 (Linux) and Konqueror 3.2 and all of them behave the same. As soon as I click on one of the subitems the menu closes such that the subitems are hidden.

    I think that a visitor would prefer that the menu stayed open such that he could select another subitem with a single click.

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Clicking a subitem loads another page. Perhaps I don't understand your question.

    BTW, here's one of my experiments which is somewhat similar.
    Last edited by MikeFoster; Jan 6, 2005 at 11:53.

  5. #5
    SitePoint Member
    Join Date
    Feb 2004
    Location
    Norway
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MikeFoster
    Clicking a subitem loads another page. Perhaps I don't understand your question.

    BTW, here's one of my experiments which is somewhat similar.
    Looks nice. Looks like you know your way around js....

    What I was trying to achive is:

    1) Clicking on "Label (level 0)" should toggle (i.e. open/close) the menu.
    2) If one of the "Label (level 0)" menues is already open and I clicking on another one, the open one should close and the one I clicked on should open.

    The thinking behind this compromise is that a visitor would probably prefer that the menu he opened stays open, allowing him to click on the vaious suditems. The reason I want to only allow just one open "Label (level 0)" menu is that I don't want the menu to grow too big (vertically), which may happen when each "Label (level 0)" menu has several subitems.

  6. #6
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I think I understand your question now but it can not apply to the SwitchMenu demo because that demo does not have nested submenus. Your suggestion can be applied to my demo because it does have nested submenus. I've applied your suggestion to variation #3 of my demo. It's certainly not the best implementation - I added it very quickly - but it seems to function properly. Feel free to ask any questions

  7. #7
    Maniacally depressed robot poncho's Avatar
    Join Date
    Dec 2004
    Location
    Belfast, N.Ireland
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mike,

    I was just about to ask for feedback on a very similar approach to showing/hiding specific divs. It seems my work has just been validated, thanks. Nice code by the way
    Perfecting the art of breaking stuff.
    Check 'em: CakePHP | TextMate

  8. #8
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks poncho! Glad it was helpful


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •