Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14611 reviews 1734 hosting providers

Questions & Answers

Exchanging data between Javascript and PHP

Oct 23, 2012 by dolphin111
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 votes
Oct 23, 2012 by FixHost
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 votes
Oct 23, 2012 by expert
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.