0

I apologize upfront for my lack of jquery knowledge. In this website I am building, a user is presented with a number of thumbnail images representing plants. When a thumbnail is clicked, a jquery popup is initiated. What I would like to be able to do is pass a php variable that has the ID of the plant over to the jquery popup to display the prper information. Any help would be greatly appreciated. Thank you.

EDIT: http://www.plantcombos.com/header/main_index.php?display=random_mix

8
  • 2
    can you post your html as well as jquery code. Or make a sample of you are trying to achieve at jsfiddle.net or jsbin.com Commented Mar 30, 2012 at 14:34
  • 2
    I would advise you post some code, or you will probably be voted down! We are here to help, not write for you! Commented Mar 30, 2012 at 14:35
  • 2
    To pass a PHP (server side) variable to Jquery (client side), you will need to make an AJAX call. Look at Jquery ajax (api.jquery.com/jQuery.ajax) Commented Mar 30, 2012 at 14:36
  • Easy Ben, I'm not looking for anyone to write the code for me. I accidentally forgot to post the url Commented Mar 30, 2012 at 14:37
  • 3
    What he means is to post the relevant code in your question. Very few of us will want to navigate to another page, click to view source, and then try to find the relevant section. Commented Mar 30, 2012 at 14:39

2 Answers 2

1

Im pretty sure you dont need to query PHP each time ... something like this would work :

<img class-"imgclick" src="/small-plant.jpg" data-id="123" />

This would be the output from your server side (php if thats what your using) - it stores the ID of the image in the data attribute

JavaScript :

$(document).ready(function() {
   $('.imglink').click(function(event) {
      event.preventDefault();
      $('dialogid')
        .data('image_id', $(this).data('id'))
        .dialog('open');
   })
})

the image id from the data attribute is then passed to the data attribute of the dialog. This attribute can be accessed using $(this).data('image_id') form within the dialog then

Sign up to request clarification or add additional context in comments.

1 Comment

I'm assuming you wanted a " instead of a : at the end of that data attribute
0

Use the jQuery AJAX method to gather data from a PHP file and display it on the page. It is very easy and you can pass any variables (parameters) you like to the page.

http://api.jquery.com/jQuery.ajax/

For example:

// This will send a request to a PHP page
$.ajax({
    url: "http://example.com/test.php",
    dataType: "html",
    success: function(data){
        // Place the returned data into your content
        $('#image').html(data);
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.