Page 1 of 1

Passing value from Js to PHP.

Posted: Fri Mar 05, 2010 8:53 am
by Goofan
Hi there.
first of all i dont know whether to post here or i the php code section as it concerns both.

I got a basic Timer in Javascript

Code: Select all

 
<html>
<head>
<script type="text/javascript">
var c=10;
var t;
var timer_is_on=0;
 
function timedCount()
{
 
if (c>0)
    {
        document.getElementById('txt').value=c;
        c=c-1;
        t=setTimeout("timedCount()",1000);
    }
    else
    {
        document.getElementById('txt').value=c;
        stopCount();
    }
 
 
 
}
 
function doTimer()
{
if (timer_is_on=1)
  {
      timedCount();
  }
 
}
 
function stopCount()
{
 
    timer_is_on=0;
    
}
</script>
</head>
 
<body>
<form>
<input type="button" value="Start count!" onclick="doTimer()" />
<input type="text" id="txt" />
</form>
 
</body>
</html>
 
I would like to have some kind of variable to pass from Js to php.
so that i pass the variable when the function stopCount() is activated it will make a variable that i can send to php.

//Thanks in advance
//Thomas

Re: Passing value from Js to PHP.

Posted: Fri Mar 05, 2010 8:57 am
by papa
PHP is parsed before JS so it's pretty hard to pass variables to it I'm afraid.

Re: Passing value from Js to PHP.

Posted: Fri Mar 05, 2010 9:04 am
by Goofan
u mean there is no way to do this?
I mean i only wanna check if the timer is 0 then do something but do it in php...
is there not a possibility to return anything to php only to check if the var c is ZERO.?

Re: Passing value from Js to PHP.

Posted: Fri Mar 05, 2010 2:06 pm
by papa
Niet

Re: Passing value from Js to PHP.

Posted: Fri Mar 05, 2010 6:47 pm
by Eran
Use AJAX or an iframe