Exchanging data between Javascript and PHP

66 views
asked Oct 23, 2012 in General by dolphin111 (320 points)
Hi

I am using a shopping cart and it has a link  showing object stockst using javascript. I have the objecy displayed on my site in. Now I want to use the text from the javascript (either available or sold) as a trigger for my variable inside the PHP If statement so if ($stock="SOLD")  then echo "id=\"hidden\". $stock is the value from the javascript. I am not sure if this is possible or not but I would appreciate any info on this.

Any help would be really appreciated
 Thanks

2 Answers

0 like 0 dislike
answered Oct 23, 2012 by FixHost (12,380 points)
First post your sold/available var to the page using the POST/get method
and  then write both javascript 1 showing and 1 hidden the field, and then use the if else statements

if($_POST['stock'] == sold) {
echo'javascript hiding  field';
}
else
{
echo 'javascript showing  the field'
}
0 like 0 dislike
answered Oct 23, 2012 by expert (14,380 points)
You can exchange data from javascript and  to php or the other way around  using cookies. In your case you can trigger cookies in your php, save them and then read them in your javascript, for this you don't have.
...