JavaScript Event "onOffClick"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nicodemas
    Recognized Expert New Member
    • Nov 2007
    • 164

    JavaScript Event "onOffClick"

    I've done some rudementary searching for a topic that would lead me to a good solution, but I have not found any so far. I was hoping Bytes might lead me to glory!


    I built my own "pop up calendar" script.

    It creates a table that has hyperlinks inside cells which, once clicked, will populate a textbox with a preformatted date.

    It positions the table absolutely at the mouse coordinates when a particular image is clicked.

    The goal I am now trying to accomplish is: when the table is showing on the screen (i.e. the table element exists in the DOM) should the user click on anything BUT the table, the table element is destroyed).

    I've tried using on onBlur() on the table, and automatically focus()'ing on the table at its creation. This works until the user tries to click the hyperlinks in the cells, at which point the onBlur fires before the click event for the hyperlink. So, no bueno.

    I tried creating an event listener at the document level which listens for a click event on anything that isn't the table (or the original element that spawns the table)... but the problem with that is if the user tries to click on the links which scroll between months in my calendar, it'll disappear!

    Can anyone think of a simple solution that I am missing?
  • Nicodemas
    Recognized Expert New Member
    • Nov 2007
    • 164

    #2
    A simple solution was not found. I ended up writing a while loop that tested the parentNode of the click event source element until it either found the calendar table or it found the BODY/HTML/undefined.

    If it found the BODY/HTML/undefined, it removed the calendar element from the DOM; otherwise, the loop was exited with a break statement.

    Comment

    Working...