2

I have a jQuery function that opens a modal popup and I have in the same file a variable in PHP like $url="iteminfo.php?ID=".$i['itmid'];($i['itmid'] is the id of some products from MySQL). The jQuery function looks like this:

<script type="text/javascript">

  $(document).ready(function(Surl) {

    var source="iteminfo.php?ID=<?echo $i['itmid']?>";
    var width = 920;
    var align = "center";
    var top = 100;
    var padding = 10;
    var backgroundColor = "#FFFFFF";
    var borderColor = "#000000";
    var borderWeight = 4;
    var borderRadius = 5;
    var fadeOutTime = 300;
    var disableColor = "#666666";
    var disableOpacity = 40;
    var loadingImage = "js/popup/loading.gif";

    $(".modal").click(function() {

        modalPopup( align,
            top,
            width,
            padding,
            disableColor,
            disableOpacity,
            backgroundColor,
            borderColor,
            borderWeight,
            borderRadius,
            fadeOutTime,
            source,
            loadingImage );

    }); 

    $(document).keyup(function(e) {
        if (e.keyCode == 27) {
            closePopup(fadeOutTime);
        }
    });

  });

</script>

It opens the respective links but the function open all of them like in a loop. How can I pass the $url into the jQuery function to open the respective link for the respective product?

2
  • Can you provide your HTML? Your Modal plugin should have ability to input a different ID on each call, this is where you grab the ID from the data from your looped array. Commented Jul 6, 2012 at 19:10
  • And where is your modalPopup function at? Commented Jul 6, 2012 at 19:14

2 Answers 2

2

For starters it would look more like this, but without seeing your HTML code its hard to say how you would be pulling out the ID of each different object with an ID.

  <script type="text/javascript">

    $(document).ready(function(Surl) {


      var source="iteminfo.php?ID=";
      var width = 920;
      var align = "center";
      var top = 100;
      var padding = 10;
      var backgroundColor = "#FFFFFF";
      var borderColor = "#000000";
      var borderWeight = 4;
      var borderRadius = 5;
      var fadeOutTime = 300;
      var disableColor = "#666666";
      var disableOpacity = 40;
      var loadingImage = "js/popup/loading.gif";


      $(".modal").click(function() {

        //get the id of what you're opening on each click event.
        var myid = ...

          modalPopup( align,
              top,
              width,
              padding,
              disableColor,
              disableOpacity,
              backgroundColor,
              borderColor,
              borderWeight,
              borderRadius,
              fadeOutTime,
              source + myid,
              loadingImage );

      }); 


      $(document).keyup(function(e) {
          if (e.keyCode == 27) {
              closePopup(fadeOutTime);
          }
      });

    });

  </script>
Sign up to request clarification or add additional context in comments.

4 Comments

here is the html <a href='javascript:void(0);' class='modal' >
@Graver haven't you already looped the data from this array to the page?
What are you trying to accomplish, loading multiple modals at once, or loading a modal for each item you already have loaded on the page?
i want to loading a modal for each item
0

Did you said that when you click in the element .modal, the right modal appear with the good content ?

And what do you mean by 'them' in 'the function open all of them' ?

Maybe you should take a look in your 'modalPopup' function.

You can store the corresponding url for every .modal element as an attribute with a php loop which browse your array.

1 Comment

When i've said "all of them" i reffered that in the modal window opens all the links from $url that is an array, all the element of that array.

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.