Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
A Javascript timer to trigger a PHP script
Old 08-01-2006, 04:12 PM A Javascript timer to trigger a PHP script
Novice Talker

Posts: 10
Trades: 0
Hi, my name is Alex, I'm working on a site, but there is one script that I have no clue how to do. I mostly work with PHP, Javascipt is pretty alien to me.

Basically, when the scripts loads, I need to display a timer that counts down from 60 seconds. Then, when it hits 0, I need to run a little PHP script to display some random numbers (the script to write the numbers I can handle, I just need the script to be triggered after the timer runs out). It would be awesome if, when the timer hit 0, the timer disappeared, so the numbers would appear in it's place, but ill be fine without it.

I dont know how tough that is, but if someone could help me a bit with the script I would be very grateful

Thanks for your time,
-Alex (Submerged)

Last edited by Submerged; 08-01-2006 at 04:13 PM..
Submerged is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-01-2006, 04:56 PM Re: A Javascript timer to trigger a PHP script
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
Instead of having JS call the PHP (which is possible via the HTTPRequest object) why not just use JS for the random number creation? I can help you with either of these solutions, but if we can eliminate a server call - all the better.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 08-01-2006, 05:07 PM Re: A Javascript timer to trigger a PHP script
Novice Talker

Posts: 10
Trades: 0
Hmmm... well, that makes it a bit different...

Basically, on page 1 i have a link. When someone clicks it, a new screen pops up, in 2 frames (top and bottom). It needs to work one of two ways:

1. When the pop-up is loaded, a variable (the 6 digit number) is carried with it, so when the 60 seconds is up it shows that number.

2. The second screen (the pop-up) creates a random 6 digit number, and then sends that back to the first page to assign to a form variable.

If either is possible (second one preferred), that would work, otherwise i could do something a bit more complicated to get it to work. THanks for your time

-Alex
Submerged is offline
Reply With Quote
View Public Profile
 
Old 08-01-2006, 07:44 PM Re: A Javascript timer to trigger a PHP script
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
Here is suggestion #2 - First, the launching page/form:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Untitled Page</title>
	</head>

	<body bgcolor="#ffffff">
	<a href="blank.html" target="newWin">Open Pop-Up Window</a>
		<form name="myForm" action="submit.php">
			<input type="input" size="6" id="theNumber" name="theNumber" value="">
			<input type="submit" name="mySubmit" value="Submit">
		</form>
	</body>
</html>
The Pop-Up:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Untitled Page</title>
		<script language="javascript"><!--
var myTimer = null;
var myTimerNum = 60;
var rNum = "";

function randomNum() {
	return Math.floor(Math.random() * 9);
}	

function createNumber() {
	for (x=0; x<6; x++) {
		rNum += randomNum().toString();
	}
}

function countDown() {
	if (myTimerNum > 0) {
		document.getElementById("timer").innerHTML = myTimerNum;
		setTimeout(countDown,1000);
		myTimerNum--;
	} else {
		createNumber();
		document.getElementById("timer").innerHTML = rNum;
	}
}

function closeWin(obj) {
	window.opener.document.getElementById("theNumber").value = rNum;
	window.close();
}

window.onload = countDown;

//-->
		</script>
	</head>

	<body bgcolor="#ffffff">
		<h1 id="timer"></h1>
		<p><button onclick="closeWin(this);">Close Window &amp; Return</button></p>
	</body>
</html>
I haven't tested it in IE, so make sure to do so. Lemme know if this works.

Last edited by funkdaddu; 08-01-2006 at 07:53 PM.. Reason: Added 6 digit number, not up-tup six digit
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 08-01-2006, 09:29 PM Re: A Javascript timer to trigger a PHP script
Novice Talker

Posts: 10
Trades: 0
Wow, that is a sweet script It should be able to handle everything i need, but if something else comes up ill let ya know. Thanks again, this is great stuff!

-Alex
Submerged is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to A Javascript timer to trigger a PHP script
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14805 seconds with 12 queries