473,387 Members | 1,722 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,387 software developers and data experts.

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 33758
ss******@mit.edu (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(form) {
var result = true;
var response = "";

var fieldValue1 = form.elements['fieldName'].value;
if (fieldValue1.match(/[\\\/]/)) { // 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="return valudateField(this)">
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.edu (Seth E Seligman) wrote in message news:<3e**********************@senator-bedfellow.mit.edu>...
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 programmatically 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
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...
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...
3
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...
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...
2
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...
10
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...
23
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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...

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.