Passing value from Js to PHP.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Passing value from Js to PHP.

Post 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
Last edited by Goofan on Fri Mar 05, 2010 9:13 am, edited 1 time in total.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Passing value from Js to PHP.

Post by papa »

PHP is parsed before JS so it's pretty hard to pass variables to it I'm afraid.
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Re: Passing value from Js to PHP.

Post 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.?
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Passing value from Js to PHP.

Post by papa »

Niet
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Passing value from Js to PHP.

Post by Eran »

Use AJAX or an iframe
Post Reply