davidm732 Posted January 19, 2009 Share Posted January 19, 2009 Hello, I am fairly new to php. I would like it to automatically close the window in 3 seconds after submit has been clicked. All the javascript code that I tryed hasn't work for me. Any help is appreciated. This is my code: <? 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> <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> </td> <td><input name="Submit" type="submit" class="button1" value="Submit!"></td> </tr> </table></td> </tr> </table> </form> <br> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/141510-how-can-i-close-my-window-in-3-seconds-after-submit-is-clicked/ Share on other sites More sharing options...
DeanWhitehouse Posted January 19, 2009 Share Posted January 19, 2009 You can't close a window you didn't open Quote Link to comment https://forums.phpfreaks.com/topic/141510-how-can-i-close-my-window-in-3-seconds-after-submit-is-clicked/#findComment-740727 Share on other sites More sharing options...
davidm732 Posted January 19, 2009 Author Share Posted January 19, 2009 Thanks for the quick reply. I'm opening this code (my site) as a pop up window. This is the code I'm using to open this as a pop up window from another page. <a href="mywebsite.php" onclick="window.open('mywebsite.php','popup','width=750,height=700,scrollbars=yes,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false">My Web Site</a> Quote Link to comment https://forums.phpfreaks.com/topic/141510-how-can-i-close-my-window-in-3-seconds-after-submit-is-clicked/#findComment-740766 Share on other sites More sharing options...
DeanWhitehouse Posted January 19, 2009 Share Posted January 19, 2009 to close then would be <a href="Javascript:window.close()">Close</a> Use a timer and put the window.close(); in a function, this is the PHP forum not JS Quote Link to comment https://forums.phpfreaks.com/topic/141510-how-can-i-close-my-window-in-3-seconds-after-submit-is-clicked/#findComment-740768 Share on other sites More sharing options...
davidm732 Posted January 20, 2009 Author Share Posted January 20, 2009 that didn't work for me , but thanks for your efforts. Quote Link to comment https://forums.phpfreaks.com/topic/141510-how-can-i-close-my-window-in-3-seconds-after-submit-is-clicked/#findComment-741297 Share on other sites More sharing options...
DeanWhitehouse Posted January 20, 2009 Share Posted January 20, 2009 Then you either didn't open the window with JS or you are doing it wrong, however please post your reply in the JS forum if you want help with it. Quote Link to comment https://forums.phpfreaks.com/topic/141510-how-can-i-close-my-window-in-3-seconds-after-submit-is-clicked/#findComment-741320 Share on other sites More sharing options...
davidm732 Posted January 20, 2009 Author Share Posted January 20, 2009 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> </td> <td><input name="Submit" type="submit" class="button1" value="Submit!" onClick="timedMsg()"></td> </tr> </table></td> </tr> </table> </form> <br> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/141510-how-can-i-close-my-window-in-3-seconds-after-submit-is-clicked/#findComment-741462 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.