user745235
user745235

Reputation:

JQuery - Open modal for dynamic links

I have several links and I need to open a modal window with a form so the user can upload a image.

I need to send the link ID to this modal window so I can make the correct upload.

I really don't know how to do that because my links have the same Id, otherwise I need to create a modal function for each link.

How do I do that?

Thanks in advance.

Upvotes: 0

Views: 1964

Answers (3)

Ric
Ric

Reputation: 1

You use unique ids for everything i.e.

<sometag id=thisdynid<?php echo your_dynamic_id_in_loop; ?> >

So now you have dynamic HTML ID elements.

Now your jQuery handlers will be coded into your loop as well.

$('#thisdynid<?php echo your_dynamic_id_in_loop; ?>').event.function(){
function code here.

}

Now you have dynamic elements with dynamic event handlers, couldn't be simpler. You can also use the 'name' attribute to fetch the ids to pass through to your php page.

<sometag id="thisdynid<?php echo your_dynamic_id_in_loop; ?>" name="<?php echo your_dynamic_id_in_loop; ?>">

Then:

$.ajax({
        url: 'your.php',
        method: 'GET',
        data: 'ID=' + $(this).attr('name'),
        success: function(data) {

etc etc.. hope this helps

Upvotes: 0

Abdul Kader
Abdul Kader

Reputation: 5842

ID's are supposed to be unique according to html standards. So you can add a dialog to a link based on the class. Which will be best way to do..

Working example here

Upvotes: 1

herman
herman

Reputation: 12305

I don't fully understand what you're trying to do with the links, but nevertheless:

  1. html IDs must be unique within the document, so if that's the source of your problem, you just need to fix that
  2. modal dialogs can be created with jQuery UI: http://jqueryui.com/demos/dialog/

Upvotes: 1

Related Questions