Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can I close my window in 3 seconds after submit is clicked?

    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>
    Last edited by dmarmolejos; 01-20-2009 at 08:23 PM.

  • #2
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    Code:
    function infoTimeout() {
    	  timeout--;
    	  if (timeout >0) {
    	   setTimeout(infoTimeout, 1000)
    	 }
    	 else
    	  window.close()
    	}
    called by

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •