473,657 Members | 2,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to close a window after form is submitted?

I'm working on a web based file manager. The rename file function creates a new window with a form allowing the user to enter a new file name. Before the form gets submitted, I want to make sure that a valid file name (no "/" or "\" characters) was entered. If the validation functions returns true, the form should be submitted and the window closed. If the function returns false the form window should stay open so the use can enter a new file name. What's the correct way to do this? When I try to add a win
dow.close function I either close the window without submitting the form, or submit the form without closing the window.
Jul 20 '05 #1
2 33791
ss******@mit.ed u (Seth E Seligman) writes:
I'm working on a web based file manager. The rename file function
creates a new window with a form allowing the user to enter a new
file name. Before the form gets submitted, I want to make sure that
a valid file name (no "/" or "\" characters) was entered. If the
validation functions returns true, the form should be submitted and
the window closed. If the function returns false the form window
should stay open so the use can enter a new file name. What's the
correct way to do this? When I try to add a win dow.close function I either close the window
without submitting the form, or submit the form without closing the
window.


To validate a form field, create a function that returns true it
the field contains a legal value and false if it doesn't. E.g.

<script type="text/javascript">
function validateField(f orm) {
var result = true;
var response = "";

var fieldValue1 = form.elements['fieldName'].value;
if (fieldValue1.ma tch(/[\\\/]/)) { // contains \ or /
result = false;
response += "Filename may not containt \"\\\" or \"/\".\n";
}

if (!result) {
alert(response) ;
}
return result;
}
</script>

Then call the function from the form's onsubmit handler, and return
its result:

<form ... onsubmit="retur n valudateField(t his)">
To close the window after the form has been sumitted, you should wait
until you are certain that the form is successfully submitted. That
means that you should close the window in the page that is returned by
the form submit, not in the one containing the form. (You should
ofcourse have a cancel button too.

If the popup window isnt doing anything except querying for a filename,
you could look into the "prompt" function.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
ss******@mit.ed u (Seth E Seligman) wrote in message news:<3e******* *************** @senator-bedfellow.mit.e du>...
I'm working on a web based file manager. The rename file function creates a new window with a form allowing the user to enter a new file
name. Before the form gets submitted, I want to make sure that a valid
file name (no "/" or "\" characters) was entered. If the validation
functions returns true, the form should be submitted and the window
closed. If the function returns false the form window should stay open
so the use can enter a new file name. What's the correct way to do
this? When I try to add a win dow.close function I either close the window without submitting the form, or submit the form without closing the window.


At least in internet-divergent internet explorer, the close() method
preempts any form submission as if the user closed the window. It is
not programmaticall y dependent on the return of any previous
instructions. So, window.close() closes the window, suddenly, and
halting whatever may have been processing, which can be useful. The
onSubmit seems to return status immediately, allowing the next
instruction.

Consider having the form handler do the window closing. It would know
when the posting process is complete.
Jul 20 '05 #3

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

Similar topics

2
18700
by: Irvin Amoraal | last post by:
Process: I have a form which uploads a file from client to server written in PHP. When the user presses the submit button, I use the "onSubmit" event to execute javascript to open a child window containing some text and an animated GIF. The javascript returns 'True' and the file is uploaded. All of that works great. Problem: Now I am trying to close the child window after the file has been uploaded. Below is the JavaScript I'm using:
11
2943
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 window finishes loading? i've been racking my brain on this for the last two days. here is the code for the parent window that i have been testing with. testfoo.htm is just a blank html page used for testing. <head>
3
1702
by: mcyi2mr3 | last post by:
Hi all I'm new to javascript and im trying to add a close button function to my certain pages of my site. I use this code: <a href='javascript:window.close();'>Close Window</a> to create a hyperlink which closes the window. However with pages which display data retrieved from a database using PHP i use a form to submit a search on the page which displays results. At the bottom of the page
1
3511
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 DB is fired, the window closes, and the opener window's (server) form is submitted (via JavaScript) (so that any form changes that were made are retained) and the newly loaded page shows the new selections from the popup window. However, the...
2
3827
by: varun | last post by:
Hi, I am using goahead webserver...i have a form, in acction attribute i am calling a c function.. after submitting the form i need to close the window and i need to reload the window which navigated to this window..... i used this javasript ....... function doUnLoad()
10
10036
by: morangolds | last post by:
Hi, I've been having a problem with C++ Windows Forms apps not "ending" when you close the form window. I've searched about this problem all over the place and most searches have lead me to believe that this has to do with unreleased form component events or event handlers. I'm comparatively new to .net and windows forms, in the sense that though I've been using them for over 2 years now, it's been rather sporadic. I work with...
23
3213
by: karen987 | last post by:
I have a form on a html page which one fills in and submits using email. The form has been opened in a pop up page, Once the form has been submitted, (emailed) I need to add some javasript to say either "thank you," in the same window and then close it. Or do something else, that the user knows his form has been submitted. The pop up window that says "thank you" can have a close link on it. I do not need to refresh the parent page or...
1
2666
by: atiq | last post by:
once the feedback is submitted the thank.html popups. however, i want this popup to only be displayed for 3 seconds and then for this window to automaticaly close it self. below is the code for thank.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script language="javascript"> settimeout("window.close()",500) </script> </head> <body>
0
8399
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8312
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8606
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7337
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4159
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.