...

View Full Version : submit form and close window



meg33
08-26-2002, 06:49 PM
Hi,

This is my problem, I have a pop up form and I want the pop up close after clicking on the submit button.

For now when I click on the submit button there is a form validation in javascript. I dont know if I can add some code in that script to tell the navigator to close the window.

there is my code :

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var submitcount=0;

function reset() {
document.spareparts.FirstName_.value="";
document.spareparts.LastName_.value="";
document.spareparts.Email_.value="";
document.spareparts.Phone_.value="";
}

function checkFields() {
if ( (document.spareparts.Email_.value.indexOf("@") == -1 ||
document.spareparts.Email_.value.indexOf(".") == -1) )
{
alert("Please enter a proper email address.");
return false;
}

else if
( (document.spareparts.FirstName_.value=="") ||
(document.spareparts.LastName_.value=="") ||
(document.spareparts.Phone_.value=="") )
{
alert("Please enter your name and phone number then re-submit this form.");
return false;
}

else
{
if (submitcount == 0)
{
submitcount++;
return true;
}
else
{
alert("This form has already been submitted. Thanks!");
return false;
}
}

}
// End -->
</script>

I wish someone can help me,
thanks

Quiet Storm
08-26-2002, 07:02 PM
<FORM onSubmit="window.close();">

meg33
08-26-2002, 07:26 PM
I tried this code but that doesn't work, probably because there is already an onSubmit action. Can I put two onSubmit action?

my code is :

<form action="mailto:email@email.com?subject=blabla" ENCTYPE="text/plain" name="name" onSubmit="return checkFields()" method="POST">

Thanks

adios
08-27-2002, 02:19 AM
Try this:

<script type="text/javascript" language="javascript">

onunload = function() {
self.close();
}

</script>

Quiet Storm
08-27-2002, 03:48 AM
<form action="mailto:email@email.com?subject=blabla" ENCTYPE="text/plain" name="name" onSubmit="return checkFields(); window.close;" method="POST">

adios
08-27-2002, 04:19 AM
Quiet Storm...
These two are equivalent:

HTML: onSubmit="return checkFields(); window.close;"

JS: Form.onsubmit = function() {return checkFields();window.close;}

Functions rarely get beyond a return statement...:(

meg33
08-27-2002, 02:23 PM
Thank you for your help but that doesn't work I don't know why but I tried your script and the window doesn't want to close.

echoless
08-29-2002, 09:35 AM
Maybe stupid suggestion but have you tried deleting your browser's temp files so that it will load the modified javascript part ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum