make layer disappear after clicking document

M

mja674s

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
 
F

Fred Oz

mja674s said:
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.

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.html>


And some sample code:

<script type="text/javascript">

function toggle(x){
var y = document.getElementById(x).style;
(y.display == 'none')? y.display='' : y.display='none';
}

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

<div
id="aDiv"
style="border: 1px dotted red;
width: 200px;
height: 200px;"
onclick="stopBubble(event);"
</div>

Thanks for help.

You're welcome.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top