Jump to content

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


davidm732

Recommended Posts

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>

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>

 

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.