...

View Full Version : How can I close my window in 3 seconds after submit is clicked?



dmarmolejos
01-20-2009, 08:15 PM
Hello everyone. My form is going to be a pop up window. How can i close it 3 seconds after the submit button is clicked? Any help is appreciated, thank you.

I need both PHP's message 'Member added successfully' to display and the window to close 3 seconds after.


This is my code (whats in red is my attempt to use setTimeout, but it seems php is overriding it : ( )

<?
include("config_fnsML.php");
$msg='';
$tdtitle = 'New Member';
$conn = db_connect();
/////////////////////////
if ($action==1){

if ($first){
$sql="INSERT INTO Mail_List(
`FirstName`,
`LastName`
)
VALUES
(
'".$first."',
'".$last."'
)";


if(mysql_query($sql)){

$msg .= 'Member added successfuly';

}else{

$msg .= 'Database ERROR:'.mysql_error();

}

}else{

$msg .= 'You did not fill in all the fields, please try again';

}

}

/////////////////////////
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><? echo $tdtitle; ?></title>
<link href="styles.css" rel="stylesheet" type="text/css">
<style type="text/css"></style>
</head>
<body>
<script type="text/javascript">
function timedMsg()
{
setTimeout("window.close()",3000);

}
</script>

<br>
<form action="<? echo $PHP_SELF; ?>?action=1" method="post" enctype="multipart/form-data" name="form1">
<table border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC" width="665">
<tr bgcolor="#F3F3F3">
<td bgcolor="#F3F3F3" class="td1"><? echo $tdtitle; ?></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><table border="0" align="center" cellpadding="2" cellspacing="0" width="100%">

<tr>
<td width="12%" class="txt1">First: </td>
<td width="88%"><input name="first" type="text" class="boxes" id="first" value="<? echo $first; ?>" size="70"></td>
</tr>
<tr>
<td width="12%" class="txt2">Last: </td>
<td width="88%"><input name="last" type="text" class="boxes" id="last" value="<? echo $last; ?>" size="70"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="Submit" type="submit" class="button1" value="Submit!" onClick="timedMsg()"></td>
</tr>
</table></td>
</tr>
</table>
</form>
<br>
</body>
</html>

ohgod
01-20-2009, 08:54 PM
function infoTimeout() {
timeout--;
if (timeout >0) {
setTimeout(infoTimeout, 1000)
}
else
window.close()
}

called by


onClick="var timeout = 3; setTimeout( infoTimeout, 1000);"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum