make layer disappear after clicking document

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

    #1

    make layer disappear after clicking document

    I'm making a date picker. It shows up fine. The problem is that I want it
    to disappear if I click outside the calendar itself. However, if I click
    *on* the calendar itself, it should not disappear, allowing me to click a
    date or cycle through the months, etc.

    Thanks for help.

    Matt


  • Fred Oz

    #2
    Re: make layer disappear after clicking document

    mja674s wrote:[color=blue]
    > I'm making a date picker. It shows up fine. The problem is that I want it
    > to disappear if I click outside the calendar itself. However, if I click
    > *on* the calendar itself, it should not disappear, allowing me to click a
    > date or cycle through the months, etc.
    >[/color]

    I think your interface is unintuitive - just put a close button
    on the calendar. It will take the user 1 click to close the
    calendar either way. If you put a button for them to click,
    then at least they know when the calendar will close and how to
    make it happen with almost zero effort.

    Your way, they have to guess what might happen - and learn that
    you like to make things happen without making it obvious.

    For the record, you must stop the calendar onclick event from
    bubbling up to the document. A full explanation is here:

    <URL:http://www.quirksmode. org/js/events_order.ht ml>


    And some sample code:

    <script type="text/javascript">

    function toggle(x){
    var y = document.getEle mentById(x).sty le;
    (y.display == 'none')? y.display='' : y.display='none ';
    }

    function stopBubble(e) {
    var e = e || window.event;
    e.cancelBubble = true; // stops IE
    if (e.stopPropagat ion) { // stops others
    e.stopPropagati on();
    }
    }
    </script>

    <div
    id="aDiv"
    style="border: 1px dotted red;
    width: 200px;
    height: 200px;"
    onclick="stopBu bble(event);"[color=blue]
    ></div>[/color]

    [color=blue]
    > Thanks for help.[/color]

    You're welcome.

    --
    Fred

    Comment

    • mja674s

      #3
      Re: make layer disappear after clicking document

      [color=blue]
      >[color=green]
      >> Thanks for help.[/color]
      >
      > You're welcome.
      >
      > --
      > Fred[/color]

      I added a close button and the functionality I was asking about.

      cancelBubble is exactly what I was looking for.

      Thanks Fred.

      Matt


      Comment

      Working...