0

So I have this site on which I have several divs. When you click on a div, a modal opens (OnClick). The modal's content is loaded remotely (modal body in another file). Within the remote link, I'm also delivering some data via GET. The data is different for each clickable div. Now if I click a div, the modal opens with the correct data. When I close that modal and try to open another one, the content displayed is still made with the data of the first clicked div. What seems to be the issue here?

That's about what I'm trying to do (simplyfied):

<div id="1" OnClick="openModal('modal_content.php?name=Peter')"></div>
<div id="2" OnClick="openModal('modal_content.php?name=John')"></div>

"openModal" is a selfmade function which opens the modal with the remote content (url in brackets). Now when I click on the first div, the modal should be

Hello Peter!

and the 2nd should be

Hello John!

First one clicked works fine. When I close that one and try to open the other, the content doesn't change.

madth3
  • 7,275
  • 12
  • 50
  • 74
schafran
  • 669
  • 6
  • 11
  • 1
    You might have to post your source code, for either I or someone else to help. – Funk Forty Niner Jun 20 '13 at 19:16
  • Possibly related to [Passing data to a bootstrap modal](http://stackoverflow.com/q/10626885/911182) – Herbert Jun 20 '13 at 19:20
  • Oh geez, this reminds me, I'm late for my mind-reading classes. See y'all on the flip side! – Funk Forty Niner Jun 20 '13 at 19:26
  • I added a code example. Hope it helps you in understanding my problem. – schafran Jun 20 '13 at 19:32
  • You might have to give the 2nd modal a different name and follow suit with the first one. For example, if inside your **JS**, say `$(#modal_1);` and in your JS call `OnClick="openModal`, you'll have to do up another like `$(#modal_2);` with a JS call like `OnClick="openModal_2` type of thing. I can't really say, and is a "calculated guess" at best, without seeing your actual full source code. – Funk Forty Niner Jun 20 '13 at 19:41
  • I would do this. The problem is, that I have up to 20 divs which should each open a modal with different data. – schafran Jun 20 '13 at 19:45
  • @FrankSchaufelberger Just an added note. You can't have the same JS call for both or added modal calls if I can say, of the same name, ie. `OnClick="openModal`. I think you'll have to find yourself another modal script. The one I like to use is called **iBox**. Here's the link http://www.ibegin.com/labs/ibox/ - all you need to do, is to add `rel="ibox"` to any `href`, image, video etc. It's the one I like best. That's the best advice I can give you Frank. **P.s.: And it works on iPhone etc. too.** – Funk Forty Niner Jun 20 '13 at 19:47
  • @FrankSchaufelberger can you post your `openModal` function? Also, have you debugged to see if your request is in fact returning the expected data? – Michael Freake Jun 20 '13 at 22:57
  • The openModal functions just toggles the modal with the remote content given as a parameter. The function and the result computed with the CGI data wors perfectly fine. The problem is that it somehow stores this data. I noticed that the
    is filled with the content thats in the modal, everytimr you open it. So I'm trying to empty() the div.modal-body tag when the modal disappeared again with .on('hidden'...). But the event doesn't fire by now. Trying to fix it over the weekend.
    – schafran Jun 21 '13 at 05:08

0 Answers0