views:

32

answers:

1

Hello,

I am using a separate PHP file as a configuration file for everything else on a basic ecommerce site.

Here is config/products.php:

$product1["short"] = "product one";
$product1["menuimgslideshowsrc"] = "image/product1.jpg";

When I hover over a button, I want to get $product1["menuimgslideshowsrc"] and swap it out with an IMG SRC.

I can do the swapping no problem, I need to know how to get the information stored in $product1["menuimgslideshowsrc"]. I assume I would use Ajax, but I am open to other ideas.

Thanks in advance.

EDIT:

Current code

    $( '.leftMenuProductButton' ).hover (
            function () {

                var currentIMG = $("#swapImg").attr("src");

                $("#swapImg").attr("src").replace(currentIMG, "NEWIMAGE");


            },
            function () {





    });
A: 

Jared, how about rendering products.php as a javascript array and including it in your page? Then you can just reference "menuimgslideshowsrc" directly from your jquery method.

products.php returns:

<script type="text/javascript">
  var productImages = new Array();
  productImages["menuimgslideshowsrc"] = "image/product1.jpg";
</script>

Your method becomes:

$( '.leftMenuProductButton' ).hover (
            function () {

                var currentIMG = $("#swapImg").attr("src");

                $("#swapImg").attr("src").replace(currentIMG, productImages["menuimgslideshowsrc"]);


        },
        function () {
Jason Slocomb
because sometimes the simplest of solutions escape me! Thank you!
Jared
I'm all about the simple. :) You're very welcome.
Jason Slocomb