PHP - How Does One Make Temporary Variables Disappear Upon Page Refresh?
Hello folks, well what I mean by temporary variables are variables like error messages or success messages that appear after a form has been submitted. I want to be able to kill these variables when the page is refreshed and return the page to its defualt state. For example, I'm making this simple page which is basically a form that ask users for some information, then upon submit, stores the in a database and prints a success message. If the form is filled out incorrectly or some form fields are left blank, then error messages are printed. What I really want is for these messages to disappear when the page is refreshed. My current model uses a second page to handle the form, and then upon succes or upon encountering an error, redirects to the form page, passing the error or success variables via the url to the form page where they are printed out. What can I do differently to achieve what I want (ie kill variables upon page refresh)? Below are the form page, and the page that handles the form respectively.
Code: [Select] <form method="post" action="send_email.php"> <div id="contact_form"> <div align="left" class="green18">Contact Us</div> <br/> <br/> <label>Your Name:</label> <input class="texta" name ="name" size="20" maxlength="49"/> <br/> <br/> <div class ="error" style="position:relative;bottom:40px;left:128px" > <?php //Retrieve the encoded errors string from send_email.php page $errors_string=$_GET['errors_string']; //Explode the decoded errors string back to an array. $errors = explode(",", $errors_string); echo $errors[0];?> </div> <label>Your Company Name:</label> <input class="texta" name ="company" size="30" maxlength="66"/> <br/> <br/> <div class ="error" style="position:relative;bottom:40px;left:128px" > <?php //Retrieve the encoded errors string from send_email.php page $errors_string=$_GET['errors_string']; //Explode the decoded errors string back to an array. $errors = explode(",", $errors_string); echo $errors[1];?> </div> <label>Subject(Optional):</label> <input class="texta" name ="subject" size="20" maxlength="49"/> <br/> <br/> <label>Email:</label> <input class="texta" name ="email" size="20" maxlength="49"/> <br/> <br/> <div class ="error" style="position:relative;bottom:40px;left:128px" > <?php //Retrieve the encoded errors string from send_email.php page $errors_string=$_GET['errors_string']; //Explode the decoded errors string back to an array. $errors = explode(",", $errors_string); echo $errors[2];?> </div> <label>Message:</label> <textarea style="float:left" class="" name ="message" cols="40" rows="3"> </textarea> <br/> <br/> <div class ="error" style="position:relative;bottom:-19px;left:-260px" > <?php //Retrieve the encoded errors string from send_email.php page $errors_string=$_GET['errors_string']; //Explode the decoded errors string back to an array. $errors = explode(",", $errors_string); echo $errors[3];?> </div> <button class="button" type ="submit" name ="submit">Submit</button> <br/> <div id ="sent" > <?php //Retrieve the user id from send_email.php page $sent=$_GET['sent']; $send_msg = urldecode($sent); echo $send_msg; ?> </div> <!--closes sent--> </div> </form> Code: [Select] <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); if (isset($_POST['submit'])) { $errors = array(); // Connect to the database. require('config/config.php'); //Check for errors. //Check to make sure they entered their name and it's of the right format. if (eregi ("^([[:alpha:]]|-|')+$", $_POST['name'])) { $a = TRUE; } else { $a = FALSE; $errors[0] = '*Please enter a valid name.'; } //Check to make sure they entered their company name. if (!empty ( $_POST['company'])) { $b = TRUE; } else { $b = FALSE; $errors[1] = '*Please enter company name.'; } //Check to make sure email is valid. if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) { $c = TRUE; }else { $c = FALSE; $errors[2] = '*Please enter a valid email address.'; } //Check to make sure they entered their message. if (!empty ( $_POST['message'])) { $d = TRUE; } else { $d = FALSE; $errors[3] = '*Please enter your message.'; } //If no errors if (empty($errors)) { //Create variables for all the post values. $name = $_POST['name']; $company = $_POST['company']; $email = $_POST['email']; $message = $_POST['message']; $ip = $_SERVER[REMOTE_ADDR]; $date = (date("Y/m/d:G:i:s")); $timestamp = ( mktime(date(H), date(i), date(s), date(m) , date(d) , date(Y))); //Formulate the insert query. $query = "INSERT INTO emails ( email_id, name, company, email, message, ip, date,timestamp) VALUES ( 0, '$name','$company','email', '$message', '$ip' , '$date', '$timestamp' )"; $result = mysql_query($query) or die("Data could not be inserted into table because: " .mysql_error()); if (mysql_affected_rows() == 1) { // Display success message $sent_msg = "Your email has been sent. We will get back to you shortly."; $sent = urlencode($sent_msg); // Display contact page header("Location: contact_page.php?sent=$sent"); exit(); }else{die("There was a problem: " . mysql_error());} //Display error messages. } else {// if errors array is not empty //Confer the errors array into a string $errors_string = implode(",", $errors); //Encode the imploded string. $error_message = urlencode($errors_string); // Display page header("Location: contact_page.php?errors_string=$errors_string"); exit(); }//End of if there are errors. }//End of if submit. ?> Also, another problem I just noticed is that, the errors[3] variable isn't getting passed back to the form page. I don't know if it's because the url can only pass so much info to a second page. The page in question can be located he http://creativewizz.com/contact_page.php Similar TutorialsOk here is what i got so far and now I am stuck. The user enters a number of how many squares (rectangles is note accurate) they wish to calculate. If its between 1 and 100 it continues, if its any other number it tells you to put in a number between 1 and 100. That was easy for me to do. If the number is between 1 and 100 it creates and input for length, width and height of each rectangle. creating the variables as it goes, i.e. "length$i" when $i is the while counter and increases to the ammount of rectangles you wished to view. Again, not that hard for me. So I am at the point where is I put in 50 I get length1 - through length30, width1 - width50, and height1 - height50. THis works great. However I now what to store those variables and calculate the area of each one via a while look which again creates an area$i variable which can be added (it would create area1 - area50 which I then wish to add together) Here is what I have so far. <?php session_start(); if (isset($_REQUEST['numpack'])) { if ($_REQUEST['numpack'] <= 0 || $_REQUEST['numpack'] > 100 ) { $error = "Please enter a number between 1 and 100"; echo $error; ?> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <table width="0" border="0" cellspacing="5" cellpadding="5"> <tr> <td colspan="2">How many Squares</td> </tr> <tr> <td> <input name="numpack" type="text" size="4" maxlength="3"></td> <td><input type="submit" name="button" id="button" value="Submit"></td> </tr> </table> </form> <?php } else { ?> <form name="form2" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <?php $i=1; while($i<=ceil($_REQUEST['numpack'])) { ?> <table width="325" border="0" cellspacing="5" cellpadding="5" style="float: left;" class="aluminium"> <tr> <td align="center" rowspan="2"><span class="transparent" style="color: #FFF; font-weight: bold;"><?=$i; ?>.</span></td> <td align="center">L</td> <td align="center">x</td> <td align="center">W</td> <td align="center">x</td> <td align="center">H</td> </tr> <tr> <td align="center"><input name="length<?=$i; ?>" type="text" size="4" maxlength="3"></td> <td align="center">x</td> <td align="center"><input name="width<?=$i; ?>" type="text" size="4" maxlength="3"></td> <td align="center">x</td> <td align="center"><input name="height<?=$i; ?>" type="text" size="4" maxlength="3"></td> </tr> </table> <?php $i++; } ?> </form> <?php } } If (!isset($_REQUEST['numpack'])) { ?> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <table width="0" border="0" cellspacing="5" cellpadding="5"> <tr> <td colspan="2">How many Squares</td> </tr> <tr> <td> <input name="numpack" type="text" size="4" maxlength="3"></td> <td><input type="submit" name="button" id="button" value="Submit"></td> </tr> </table> </form> <?php } ?> Now I was reading up on session data and think this might be the best way to go, but again how do I do this? and two I want to make sure that if there are 2 people accessing it at the same time, it does not change the variables on them... (i.e. user one puts in 50 values, and user two puts in 50 different values I do not want cross contamination) Any ideas on how to proceed? i got a submit button... if user click the submit button iwant to page will auto referesh... can someone teach me When I asked how to make this Log In Form disappear once it performs it's function:
<form action="../login.php" method="post" accept-charset="UTF-8" class="middletext" onsubmit="javascript:this.style.display='none';"> <p> <input type="text" size="20" name="user_name_login" id="user_name_login" value="ENTER USERNAME" style="color:#D9D9D9" style="vertical-align:middle"; onfocus="if (this.value=='ENTER USERNAME') {this.value=''; this.style.color='#696969';}" > <input type="text" size="20" name="password_login" id="password_login" value="ENTER PASSWORD" style="color:#D9D9D9" style="vertical-align:middle"; onfocus="if (this.value=='ENTER PASSWORD') {this.value=''; this.style.color='#696969';}" > <input type="hidden" name="cookie_time" value="10080" /> <img src="../themes/default/images/arrow-red.png" alt="" /><input type="submit" style="outline:grey" font-size="5px" value="[var.lang_login_now]" class="button-form2" /> <input type="hidden" name="submitted" value="yes" /> <input type="hidden" name="remember_me" value="remember_me" /> </p> </form> </div> <!--Begin Sub-Navigation. This only appears when a user is logged in.--> <div class="container1"> <div class="menu1"> <div class="sub-nav"><a href="../index.php"></a> <img src="../themes/default/images/arrow-red.jpg" style="vertical-align:middle" alt="" /><a href="../members/[var.user_name]"> my account</a><img src="../themes/default/images/arrow- red.jpg" style="vertical-align:middle" alt="" /> <a href="../credits.php">[var.lang_my_credits]: [var.member_credits]</font></a><img src="../themes/default/images/arrow-red.jpg" style="vertical-align:middle"><a href="../logout.php">[var.login_out]</a> <!--[onload;block=div;when [var.loggedin]=1;comm]--> </div>I was given this line of code: if($_SESSION['loggedin'] == true){ //dont show form } else { //show form }But I don't know how/where to integrate it into the Form. Any help will be appreciated. I'm using a popular PHP script for my web site, which uses main_1.htm for the header and footer, and inner_index.htm for the main part of the home page. Also, of course it has index.php. How can I set up a duplicates of these files to work on and test changes to the home page, before I actually deploy the changes on to my live site's home page? Thanks Ok, I've spent a good part of the day trying to figure out what is going wrong with a client site. I introduced a link within document to send readers from the blogs home page to the comments section of individual posts. It's straight forward right? HTML1, been doing these kind of links for more than ten years. #respond at the end of the normal URL in a normal anchor tag should bring the browser to id="respond" or name="respond" within the document. Right? But, a.) it doesn't. And b.) once it makes a jump everything above that point disappears. Space fills out to the same page height as if it existed but you can't scroll up. You can see it in action at http://www.thebouncingbead.com/blog/ by clicking "Add Your Comment (0)" under the title of any post. Can anyone see what might be causing this problem or experienced something similar before? This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=349338.0 I need to create a loop where I can cycle through three variables and determine the maximum output. Here is an example... First loop $var_one = .01 $var_two = .01 $var_three = .98 run calculation for vars Second Loop $var_one = .02 $var_two = .01 $var_three = .97 run calculation for vars This loop would run through ALL possible values making sure that the total of all variables would always equal 1. There could be more than three variables so this will be dynamic. I have no idea how to make this. Any thoughts? Hello, to start off I am very new to this and trying to learn as I go by using sample code and putting things together as I need them. I am working on a basic database editor that will make a select able list from a sql table. In this case, "Employees". Then, after I select a name from that list it gives me the option to alter that information and save it. What I am missing however, is the option to pre-fill what the database already has while in the edit part. The drop down menu only shows the Employee name. So when I select the name, only the EmpID variable is transferred to the next part. I want all fields pre-filled out by defining variables from the SQL table.
So I cant figure out how to call the database, then the table, Find the PRIMARY KEY (which is the EmpID) and create variables from (FirstName, LastName and Pay), but only for the EmpID that was slected before hand. How can I do this? Once I can make those variables, I can use them to pre-fill the text areas..
Thank you in advance. Also if needed I will post the code I have so far.
<html> <head> <title>Edit Employee</title> </head> <body> <?php $dbhost = 'localhost'; $dbuser = 'Labor'; $dbpass = '***********'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); // Check connection if(! $conn ) { die('Could not connect: ' . mysql_error()); } if(isset($_POST['save'])) { $EmpID = $_POST['EmpID']; $FirstName = $_POST['FirstName']; $LastName = $_POST['LastName']; $Pay = $_POST['Pay']; $OrgEmpID = $_POST['OrgEmpID']; $sql = "UPDATE Employees SET EmpID='$EmpID', FirstName='$FirstName', LastName='$LastName', Pay='$Pay' WHERE EmpID='$OrgEmpID'"; mysql_select_db('Labor'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not update data: ' . mysql_error()); } echo "Updated data successfully\n"; } else { if(isset($_POST['select'])) { $EmpID = $_POST['EmpID']; $FirstName = $_POST['FirstName']; $LastName = $_POST['LastName']; $Pay = $_POST['Pay']; $OrgEmpID = $_POST['EmpID']; echo ' Update Employee <form method="post" action="'.$_PHP_SELF.'"> <table width="400" border="0" cellspacing="1" cellpadding="2"> <tr> <td width="100">Employee ID: </td> <td><input name="EmpID" type="text" id="EmpID" value="'.$EmpID.'"></td> </tr> <tr> <td width="100">First Name: </td> <td><input name="FirstName" type="text" id="FirstName" value="'.$FirstName.'"></td> </tr> <tr> <td width="100">Last Name: </td> <td><input name="LastName" type="text" id="LastName" value="'.$LastName.'"></td> </tr> <tr> <td width="100">Hourly Pay: </td> <td><input name="Pay" type="text" id="Pay" value="'.$Pay.'"></td> </tr> <tr> <td width="100"> </td> <td> </td> </tr> <tr> <td width="100"> </td> <td> <input type="hidden" name="OrgEmpID" value="'.$OrgEmpID.'"> <input name="save" type="submit" id="save" value="Save"> </td> </tr> </table> </form> '; } else { ?> <form method="post" action="<?php $_PHP_SELF ?>"> <table width="400" border="0" cellspacing="1" cellpadding="2"> <tr> <td width="100">Select Employee to Edit</td> <td></td> </tr> <tr> <td width="100"> <select name="EmpID" id="EmpID"> <option value='EmpID' disabled='disabled' selected='selected'>Please select a name</option> <? mysql_select_db('Labor'); $result = mysql_query('SELECT EmpID, FirstName, LastName, Pay FROM Employees'); while ($row = mysql_fetch_array($result)) { echo '<option value="'.$row{"EmpID"}.'">'.$row{"FirstName"}.' '.$row{"LastName"}.'</option>'; } ?> </select> </td> <td> </td> </tr> <tr> <td width="100"> </td> <td> <input name="select" type="submit" id="select" value="Select"> </td> </tr> </table> </form> <?php } } ?> <br> <a href="index.php">Home</a> </body> </html> is there an easy way to make all variables equal to zero (as opposed to empty) at the end of a loop?
rather than
$a =0;
$b=0;
etc etc
as i have hundreds and hundreds of the things and need to reset them all to equal a value of zero.
thank you in advance.
I'm having trouble getting my script to refresh the page. If the username, password match it falls into this if statement. Sometimes it works and other times and won't refresh the page automatically. I'm trying to use this line to refresh the page Code: [Select] echo "<meta http-equiv='refresh' content='=2;index.php' />"; Here is the if statement Code: [Select] if(mysql_num_rows($checklogin) == 1) { // store the row returned from query $row = mysql_fetch_array($checklogin); // get email address from row returned $email = $row['EmailAddress']; // store user variables in session array $_SESSION['Username'] = $username; $_SESSION['EmailAddress'] = $email; $_SESSION['LoggedIn'] = 1; // boolean echo "<h1>Success</h1>"; echo "<p>We are now redirecting you to the member area.</p>"; echo "<meta http-equiv='refresh' content='=2;index.php' />"; } here is the entire index.php file Code: [Select] <?php include "base.php";?> <!-- base.php contains session_start() --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>User Management System (Tom Cameron for NetTuts)</title> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <div id="main"> <?php // check if user is already logged in if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { ?> <h1>Pitch Shark Member Area</h1> <p>Thanks for logging in! You are <b><?=$_SESSION['Username']?><b> and your email address is <b><?=$_SESSION['EmailAddress']?></b>.</p> <ul> <!-- link that runs logout.php script --> <li><a href="logout.php">Logout.</a></li> </ul> <?php } // check login form elseif(!empty($_POST['username']) && !empty($_POST['password'])) { // strip away malicious code $username = mysql_real_escape_string($_POST['username']); // encrypt password $password = md5(mysql_real_escape_string($_POST['password'])); // return all matches to username and password $checklogin = mysql_query("SELECT * FROM haas12_test.users WHERE Username = '".$username."' AND Password = '".$password."'"); // if there is a match if(mysql_num_rows($checklogin) == 1) { // store the row returned from query $row = mysql_fetch_array($checklogin); // get email address from row returned $email = $row['EmailAddress']; // store user variables in session array $_SESSION['Username'] = $username; $_SESSION['EmailAddress'] = $email; $_SESSION['LoggedIn'] = 1; // boolean echo "<h1>Success</h1>"; echo "<p>We are now redirecting you to the member area.</p>"; echo "<meta http-equiv='refresh' content='=2;index.php' />"; } // if there information entered could not be found else { echo "<h1>Error</h1>"; echo "<p>Sorry, your account could not be found. Please <a href=\"index.php\">click here to try again</a>.</p>"; } } // display login form with link to register form else { ?> <h1>Member Login</h1> <p>Thanks for visiting! Please either login below, or <a href="register.php">click here to register</a>.</p> <form method="post" action="index.php" name="loginform" id="loginform"> <fieldset> <label for="username">Username:</label><input type="text" name="username" id="username" /><br /> <label for="password">Password:</label><input type="password" name="password" id="password" /><br /> <input type="submit" name="login" id="login" value="Login" /> </fieldset> </form> <?php } ?> </div> </body> </html> After I submit form data how can I force the page to refresh so I can see the changes take effect? I know this is probably a very basic question. i have already echoed title and included that file in my php script, a header file.... but now i want to refresh my php script if the comment has been successfully added else remain in the same page....it remains in the same page now with just a msg that the comment is added....but i cant see the comment unless i refresh the page... i get he headers already sent error when i put a header() there as i have included another php file which already echoes title to screen....so what do i do now? i want the comment to be displayed to the user once he clicks on save and not make it tedious for him to refresh....any suggestions?any way around? Is it possible to refresh parent page before header() So let say i have 2 page, and 1st page is parent page and the other is pop up window Assume that there is an execution of certain script at the pop up window and it redirected to another page and redirected back again to that page As certain data being displayed in both pop up window and parent page..so i wish to have parent page being refreshed once pop up window execute header() is that possible?? anyone know how to get rid of an echo when you hit refresh on the browser? My browser is remembering the echo from with in a if statement when refresh is hit even if the if statement remains false on refresh. I have an issue with refreshing pages on the website. I have a simple code using php to login to the website fill in a form and exit. The code works fine and adds the enterd data correctly in the table in MySql. I have another link where the user can retrieve the recods to update any fields after logging in. The problem I encountered was that the retreving records page does not show the newly added records until the page is refreshed on the server. Whenever the new record does not show, I just open the php code page save without making any changes to the code (just to enforce new time stamp), upload the page to the server only when I do that the new record shows. I would appreciate any help to solve this problem and not having to upload the page to get it to work. Thanks, MB Okey, after hours and hours of googling...all i found was some snippet that works so far that it displays the success and error message, however doesn't do any queries. Basically, what i need is this: I have a textarea where a user submits he's status a.k.a what he's doing, but then the page refreshes (you know, the oldschool plain php/html). However, I know this is doable via jQuery / Ajax ... all i need is a proper code that actually works. Hi All, I was wondering if there is any way that a PHP page can update itself when a row in a DB is added or updated? I am trying to get a feed up and running and want it to update when a row is updated/inserted. Thanks Matt I would like the page orderform.php to reload or refresh to normal after I click this link: this is what i have and this link is on a different page though... if($myError==true) echo "<br /><br />Click here to <a href='orderform.php?nocache='.time().'>go back...</a>"; else header("location: orderform.php"); Hi everyone, Im using the code below to insert an item to auction, then calculate and display the time remaining until the auction ends. As soon as the confirm auction submit button is clicked, the item appears at auction straight away, however the time remaining is 0s, i have to refresh the page in order to get the end time to appear correctly. Does anybody know why this is happening and what i can do to get the correct end time to appear straight away? Thanks <?php if ($_POST['confirm_auction']) { foreach ($_POST['checkbox'] as $checked) { $add_auction_query = mysql_query("SELECT * FROM offers WHERE seller='$username' AND buyer='$buyer' AND item='$checked'"); while ($row = mysql_fetch_assoc($add_auction_query)) { $starting_bid = $row['offer']; $current_bid = $starting_bid; $start_date = date("Y-m-d H:i:s"); $end_date = date("Y-m-d H:i:s", strtotime("+1 week")); mysql_query("INSERT INTO auctions VALUES ('','$checked','$username','$starting_bid','$current_bid','$buyer','1','At Auction','$start_date','$end_date')"); mysql_query("INSERT INTO bids VALUES('','$checked','$username','$buyer','$starting_bid','$start_date')"); mysql_query("UPDATE offers SET seller_status='At Auction',buyer_status='At Auction' WHERE item='$checked'"); } echo "Offer(s) Sent to Auction"; } } $x = 0; while ($auction_row = mysql_fetch_assoc($auction_query)) { $then = strtotime($auction_row['end_date']); $now = time(); $diff = $then - $now; $weeks = floor($diff / (60*60*24*7)); $diff = $diff - ($weeks * (60*60*24*7)); $days = floor($diff / (60*60*24)); $diff = $diff - ($days * (60*60*24)); $hours = floor($diff / (60*60)); $diff = $diff - ($hours * (60*60)); $minutes = floor($diff / 60); $diff = $diff - ($minutes * 60); $seconds = $diff; ?> <html> <table> <tr> <td> <?php if ($week > 0) {echo $weeks . "w ";} if ($days > 0) { echo $days . "d ";} if ($hours > 0) {echo $hours . "h ";} if ($minutes > 0) { echo $minutes . "m ";} if ($hours < 1) {echo $seconds . "s";} ?> </td> </tr> </table> </html> <?php $x++; } ?> Hey guys! Merry Christmas!!!! Here's my problem. I have a script where I use the code include("pagerefresh.php"); where pagerefresh.php is <?php $page = $_SERVER['PHP_SELF']; $sec = "0"; header("Refresh: $sec; url=$page"); ?> I use the include function several times on the page and everything's cool with it. But once I put this: <html> <head> <title>Title</title> <script type="text/javascript"> <?php some mysql function include("timecounter.js"); ?> </script> </head> in the page, the following error pops out whenever I use some of the form functions in the page. I read the php.net manuals and discovered that the include part should come before Code: [Select] Warning: Cannot modify header information - headers already sent by (output started at D:\Hosting\rrr\html\rrr\rrr\rrr.php:191) in D:\Hosting\rrr\html\rrr\rrr\pagerefresh.php on line 4 Oh, and I also put the javascript code directly into the page, without the include function, the same results pop out. :/ . Though I suspect that it is immaterial here, the javascript code is: Code: [Select] var month = '<?php echo "$cmonth"; ?>'; // 1 through 12 or '*' within the next month, '0' for the current month m var day = '<?php echo "$cday"; ?>'; // day of month or + day offset d var dow = 0; // day of week sun=1 sat=7 or 0 for whatever day it falls on var hour = '<?php echo "$chour"; ?>'; // 0 through 23 for the hour of the day H var min = '<?php echo "$cminute"; ?>'; // 0 through 59 for minutes after the hour i var tz = -7; // offset in hours from UTC to your timezone var lab = 'cd'; // id of the entry on the page where the counter is to be inserted function start() {displayCountdown(setCountdown(month,day,hour,min,tz),lab);} loaded(lab,start); // Countdown Javascript // copyright 20th April 2005, 1st November 2009 by Stephen Chapman // permission to use this Javascript on your web page is granted // provided that all of the code in this script (including these // comments) is used without any alteration // you may change the start function if required var pageLoaded = 0; window.onload = function() {pageLoaded = 1;} function loaded(i,f) {if (document.getElementById && document.getElementById(i) != null) f(); else if (!pageLoaded) setTimeout('loaded(\''+i+'\','+f+')',100); } function setCountdown(month,day,hour,min,tz) {var m = month; if (month=='*') m = 0; var c = setC(m,day,hour,tz); if (month == '*' && c < 0) c = setC('*',day,hour,tz); return c;} function setC(month,day,hour,tz) {var toDate = new Date();if (day.substr(0,1) == '+') {var day1 = parseInt(day.substr(1));toDate.setDate(toDate.getDate()+day1);} else{toDate.setDate(day);}if (month == '*')toDate.setMonth(toDate.getMonth() + 1);else if (month > 0) { if (month <= toDate.getMonth())toDate.setFullYear(toDate.getFullYear() + 1);toDate.setMonth(month-1);} if (dow >0) toDate.setDate(toDate.getDate()+(dow-1-toDate.getDay())%7); toDate.setHours(hour);toDate.setMinutes(min-(tz*60));toDate.setSeconds(0);var fromDate = new Date();fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());var diffDate = new Date(0);diffDate.setMilliseconds(toDate - fromDate);return Math.floor(diffDate.valueOf()/1000);} function displayCountdown(countdn,cd) {if (countdn < 0) document.getElementById(cd).innerHTML = "Building Completed"; else {var secs = countdn % 60; if (secs < 10) secs = '0'+secs;var countdn1 = (countdn - secs) / 60;var mins = countdn1 % 60; if (mins < 10) mins = '0'+mins;countdn1 = (countdn1 - mins) / 60;var hours = countdn1 % 24;var days = (countdn1 - hours) / 24;document.getElementById(cd).innerHTML = days+' days and '+hours+' : '+mins+' : '+secs;setTimeout('displayCountdown('+(countdn-1)+',\''+cd+'\');',999);}} Thanks in advance. And Merry Christmas!!!!! Thauwa |