I had a javascript counter. If counter = 0, then price change. I want to assing javascript price var value of php variable. But price increases once in php and it's all.
<?php global $p; $p = 1000; ?>
var pr = <?php echo $p;?>;
function downCounter(tim)
{
var t;
counter=tim-1;
var elem=document.getElementById('counter');
var price= document.getElementById('price');
var days = parseInt(counter / 86400),
hours = parseInt(counter / 3600) % 24,
minutes = parseInt(counter / 60) % 60,
seconds = counter % 60,
hours = (hours < 10) ? '0' + hours : hours;
minutes = (minutes < 10) ? '0' + minutes : minutes;
seconds = (seconds < 10) ? '0' + seconds : seconds;
elem.innerHTML=(days ? days + dayname : '') + hours + ':' + minutes + ':' + seconds;
price.innerHTML=(pr);
if (counter==0)
{
downCounter('43200');
<?php $p += 500; ?> <-- works once
pr = <?php echo $p; ?>;
} else {
clearTimeout(t);
t=setTimeout("downCounter('+"+(tim-1)+"')", 1000);
}
return false;
}
downCounter('43200');
</script>
thanks to all, but how i can protect my pr variable from changing in source and then send via ajax?