0

I have a site where I am triggering a modal from a set of links. Is there a way to pass a reference of the link itself to the modal?

My current implementation is available here: http://138.197.123.25/ the left sidebar links will simply launch a modal window and ask for location; when they choose a location for that specific item.

The problem is if someone clicks on the side menu for Party Packages, then chooses say San Diego from the modal choice, they are taken to http://138.197.123.25/location/san-diego-rentals/, but what I would like is for them to go directly to the item and location they chose, so in this example, I would like them to go to directly to http://138.197.123.25/location/san-diego-rentals/party-packages/.

I am not sure how to pass a reference of the link that is clicked to launch the modal, so I can add the type of item to the location and build the final URL.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
Charles Smith
  • 3,201
  • 4
  • 36
  • 80
  • 1
    I cleaned up your question and removed references to django, since it is not relevant to your problem. – Burhan Khalid Apr 13 '17 at 03:13
  • Possible duplicate of [Passing data to a bootstrap modal](http://stackoverflow.com/questions/10626885/passing-data-to-a-bootstrap-modal) – Burhan Khalid Apr 13 '17 at 03:16
  • Have you tried using the `data-*` attribute? That could work. https://www.w3schools.com/tags/att_global_data.asp – root Apr 13 '17 at 03:18

1 Answers1

0

@burhan-khalid Thank you for the link; that helped me greatly. Here is my working code with the sidebar data param being append to an href in the modal.

sidebar static menu (initiates modal) - link 1

Currently there are about 20 sidebar links that open the modal, and each have a data attribute assigned. The link below has a data attribute of data-pr but others have custom attributes like data-cg (carnival games) or data-tp (themed-parties) etc...

...
<div class="ss_button" data-id="party-packages"><a href="#" data-toggle="modal" data-target=".bs-example-modal-lg">Party Packages</a></div>
...

modal window with 1 of four link choices (initiates modal) - link 2

...
<div class='col-md-3'>
   <a href="/location/san-diego-rentals/"><span class='city'>San Diego</span></a>
</div>
...

script

<script>
    $(document).on("click", ".ss_button", function () {
        var rentals = $(this).data('id');
        $('.modal-content a').attr('href', function () {
            return this.href + rentals;

        });
    });
</script>
Charles Smith
  • 3,201
  • 4
  • 36
  • 80