0

My question here is based on a product that holds different colours.

If I click on an image I need to be able to change the value of the variable.

At the moment it picks up the parent product colour, however if I click on a different image I need the below $value to change to the tray data that's stored in the image tag.

<img class="product" title="Image 1" tray="A.1.A" src="" />
<img class="product" title="Image 2" tray="A.2.A" src="" />
<img class="product" title="Image 3" tray="A.3.A" src="" />

<?php $value = get_field('product_tray'); ?>

The JavaScript I have been using for the title was the following (works fine) but I need to integrate with the variable this time.

$(".product").live('click', function(){
    $("#content").html($(this).attr('title'));
});
tebrown
  • 153
  • 4
  • 19
  • 3
    [This is what you're looking for](http://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript), but instead of getting data *from* your PHP script, you would be sending data *to* your PHP. –  Feb 01 '16 at 23:12
  • @TinyGiant - Still having trouble with this. I have read most of the documentation on that thread but don't quite understand. For what I want to achieve - would it be much code? – tebrown Feb 04 '16 at 20:33
  • No, you just need to do an AJAX request to your page, you have to realize that once the page is served to the client, your PHP script is finished. So you need to design your PHP script to be able to receive information through GET or POST requests from the client, then output a response based on the received input which can then be interpreted in the onload event listener of the AJAX request. All of this depends entirely on the PHP script, and the JavaScript that you're using, which if posted here would make the question far too broad. –  Feb 04 '16 at 21:07

0 Answers0