473,411 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Cannot close popup window after submit

Hi,

I have a popup window that opens from a page on my website.
This popup is a form with several fields.
Upon submit button it redirects to a server side ASP page which writes
all data to the DB.

I would like the popup to close immediately after the submit button is
clicked, and data is saved, (or cancel button) - but this does not
happen.
The popup window remains open, even though I have a "return false;"
after window.open in the onclick event.

What am I missing?

<a href="myurl.asp" onclick="window.open('myurl.asp',
'title','toolbar=no,width=700,height=600'); return false;">post a
note</a>;

Thanks, Gabi.

Jan 22 '07 #1
4 21250
Hi,

Gabriella wrote:
Hi,

I have a popup window that opens from a page on my website.
This popup is a form with several fields.
Upon submit button it redirects to a server side ASP page which writes
all data to the DB.

I would like the popup to close immediately after the submit button is
clicked, and data is saved, (or cancel button) - but this does not
happen.
The popup window remains open, even though I have a "return false;"
after window.open in the onclick event.

What am I missing?

<a href="myurl.asp" onclick="window.open('myurl.asp',
'title','toolbar=no,width=700,height=600'); return false;">post a
note</a>;

Thanks, Gabi.
You misunderstood what "return false" does here. It only tells the
browser, that the "href" part of the link must not be executed after the
"onclick" event has been executed. If you don't return false, then the
browser will open the window, and then (when the script is finished), it
will navigate to the URL written in the HREF part.

If you want to close the pop-up after submitting the link, you can use
this code:

<input type="button" value="submit"
onclick="this.form.submit();top.close();" />

Alternatively, you can also use the onsubmit event of the form.

<form action="..."
onsubmit="top.close();">

....

</form>

Note also that pop-ups are rather not recommended, and you may consider
an inline floating DIV instead.

Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jan 22 '07 #2
Thanks a lot!!

Another question:
I want to refresh the opener page immediately after closing the popup.
How do I do that?

Why are popups not recommended?
Can you show me how to use an inline floading DIV instead?

Thanks again, Gabi.

Jan 22 '07 #3
Hi,

Gabriella wrote:
Thanks a lot!!

Another question:
I want to refresh the opener page immediately after closing the popup.
How do I do that?
If you keep the popup, before you close the pop-up with self.close(),
you can call

opener.location.reload();

"opener" is a keyword with a reference to the opener window. The Window
object has a location property, which is an instance of the Location
object, which you can reload.

Why are popups not recommended?
For many reasons, mostly explained here:
http://developer.mozilla.org/en/docs...dow.open.28.29

In short: You can never be sure that a popup will actually be displayed
(because of popup blockers), and it annoys users.

For the record, I still have a few apps using popups, but I am slowly
removing them when I work on these apps.
Can you show me how to use an inline floading DIV instead?
You can use this kind of HTML/CSS code to position a DIV absolutely:

<div style="position: absolute;
top: 100px;
left: 200px;">

....

</div>

Additionally, you can play with the "display" property in the style to
show and hide the DIV, for example:

<div id="divForm"
style="position: absolute;
top: 100px;
left: 200px;
display: none;">

....

</div>

and then:

var nDiv = document.getElementById( "divForm" );
if ( nDiv
&& nDiv.style
&& nDiv.style.display )
{
nDiv.style.display = "block";
}

Note that since the DIV is inline (not a separate window), when you
submit the form, the whole page will be refreshed, which is what you
wanted from the start.

If you want to avoid refreshing the page, then you must resort to AJAX
to post your data to the server.

Thanks again, Gabi.
HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jan 23 '07 #4
ASM
Gabriella a écrit :
Another question:
I want to refresh the opener page immediately after closing the popup.
How do I do that?
You must do it *before* to close the popup :

opener.location.reload();
or (depends what you want) :
opener.location = opener.location

Vedere gli esempi dati al vostro compatriota :
http://stephane.moriaux.perso.wanado...uc/tutticanti/
Why are popups not recommended?
because most of surfer have anti-popups that could block yours.
Because Firefox by default open accepted popups in a tab (and this tab
is not allways automatically opened)
Can you show me how to use an inline floading DIV instead?
ask to Google : tolltip
http://www.walterzorn.com/tooltip/tooltip_e.htm
very much heavy and hard to understand :
http://developer.yahoo.com/yui/container/tooltip/

ask to Google : modal dialog
http://sublog.subimage.com/articles/2006/01/01/subModal

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Jan 24 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: JSjones | last post by:
when a form is submitted from the main window i want a pop up window to open from the onclick event. i have that working, now how can i close the pop up window from the main window after the main...
4
by: Sjaakie Helderhorst | last post by:
Hi, I wrote an ASP-page which allows friends to upload a datafile which will be processed and stored in a database. Because large files take some time to process I want to open a popup 'Please...
4
by: ...D. | last post by:
OK. I am halfway decent with HTML. Now I want to try javascript for some things that HTML cannot do. I have looked over a tutorial & all. What I want to do is create a button, that when...
5
by: Mardy | last post by:
Hello I'm trying to use a pop-up to capture some information and then return the user to a datagrid containing the changes made in the pop-up. I have the database update working and the pop-up...
1
by: Matt Jensen | last post by:
Howdy I've got a ASP.NET webform page that pops up a window for a user to make a selection. Once they make a selection in this popup window, the form in the popup is submitted an update to the...
5
by: midnight_use_only | last post by:
hi all, quick question, how do you submit a form to a parent window from a child popup window? i have the following and all online documentation *suggests* that it should work but it does NOT: ...
1
by: sjsean | last post by:
In an asp page I have the following scenario happening (or would like to happen) person picks a menu item in main page which opens a popup window that allows customization of that menu item. ...
1
by: dittu | last post by:
How to close the popup window when submitting the form? I have a sample.jsp. In that page one button is there. when button pressed, open popup window contains one "text box" and one " submit...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.