troubleshooting Question

Can I change the value of a PHP variable using Javascript?

Avatar of sabecs
sabecs asked on
JavaScriptPHP
15 Comments1 Solution1854 ViewsLast Modified:
Can I change the value of a php variable using javascript?
For example I have a few onmouseOver events that I want to change the value of a PHP variable $spec

onmouseOver='bigimage.src="<?php echo $imagebig1; ?>";<?php $spec = 1; ?>'
onmouseOver='bigimage.src="<?php echo $imagebig2; ?>";<?php $spec = 2; ?>'
onmouseOver='bigimage.src="<?php echo $imagebig3; ?>";<?php $spec = 3; ?>'

and then my Buy Button has the following
onClick="location.href='javascript:AddItem(<?php echo $rs_prods['PID']?>,1,<?php echo $spec; ?>)'"

function AddItem($PID, $qty, $spec)
      {
            var item = $PID;
            var qty = $qty;
            var spec = $spec;
            
            alert(spec);
            self.location = "addtocart.php?action=add_item&id="+item+"&qty="+qty+"&spec="+spec;
            }

I doesnt appear to be working as it just sets $spec equal to 3 every time

Thanks.
ASKER CERTIFIED SOLUTION
psimation

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 15 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros