Forum Moderators: open

Message Too Old, No Replies

Popup closes too early

onBlur causes another popup to close before the click to it gets processed

         

webmonkey77

2:39 pm on Jul 6, 2008 (gmt 0)

10+ Year Member



I wrote a little calendar popup that appears when you click on an input field. If you then click on one of the days in the calendar, it fills the input field with the appropriate date and closes the calendar.

However, I'd also like the calendar to close (without doing anything) if you click anywhere else on the page. I tried putting an onBlur in the input element, which works, except that if I click on the calendar, the onBlur causes it to close before the click causes the input field to update.

I tried a cover-like method where there's a transparent div covering the whole page, behind the calendar widget but above the main divs, so that if you click anywhere, the cover intercepts the click and closes the div. However this means you have to click twice to focus any other element, and it also means the scrollwheel doesn't work while the cover div is up.

(FYI, the input field pops up the calendar on an onClick event. I also tried onFocus, with the same results as above.)

If anyone has any advice or suggestions, I'd greatly appreciate it. Thanks!

rocknbil

3:52 pm on Jul 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you try ...

Opening window:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<!-- doctype on one line -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Close Window</title>
<script type="text/javascript">
function newWin(url) {
var day = new Date();
var id=day.getTime();
var params = 'width=400,height=400,scrollbars,resizable';
var win=open(url,id,params);
return false;
}
</script>
</head>
<body>
<form>
<input type="text" id="txtfld" onClick="return newWin('win.html');">
</form>
</body>
</html>

Pop up:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<!-- doctype on one line -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled</title>
<script type="text/javascript">
window.onload=function() {
document.getElementById('txtfld').onblur=function() {
window.opener.document.getElementById('txtfld').value=
document.getElementById('txtfld').value;
window.close();
}
}
</script>
</head>
<body>
<form>
<input type="text" id="txtfld">
</form>
</body>
</html>

Initially misunderstood problem, this should do it . . .

webmonkey77

5:28 pm on Jul 6, 2008 (gmt 0)

10+ Year Member



Sorry, I wasn't clear; the popup is a Javascript popup, not a new window. It's just a hidden div at a higher z-index.

webfoo

11:55 pm on Jul 13, 2008 (gmt 0)

10+ Year Member



I'm at a loss for this one. I don't think it'll work, but give this a try:

<body onClick="{hide the calendar}">

I think you'll run into the same problem, but if the date gets put in the input element first, it'll work.