1

I have a table of data being produced with JavaScript. At the end of each row is an image, which is clickable. When clicked, a popup appears containing information based on the row.

I am using the second example on here: http://www.abidibo.net/projects/js/moopopup/demo

Basically, how I have it setup now is this:

The function;

    function popup() {

    var mp_instance = new moopopup({ 
        overlay: true, 
        title: 'Copy server address', 
        html_node: 'mynode',
    }); 
    mp_instance.display();
}

make the popup, appear, using a div which is initially hidden

<div id="mynode" style="display:none">Content.</div>

The image then uses onclick to make the popup run.

onclick='popup();'

Now this works with static data, however each row has different content I want to put in to the popup. So i'm confused about how I would make each popup individual to the row, without creating loads of functions with an ID on the end, which basically all do the same thing.

http://www2.lethal-zone.eu/servers/tf2-servers

The image at the end of each row; when clicked shows some extra content...

Alias
  • 2,983
  • 7
  • 39
  • 62

1 Answers1

1

You generally would want to pass some information to the one function as parameters and then use those parameters to choose the content. For example, pass some ID to the function:

onclick="popup(1);"

function popup(id) {
    // do something with id to choose the content
    // snip...
}
jbabey
  • 45,965
  • 12
  • 71
  • 94
  • Thanks! Also, when this popup appears, I would also like it to be already selected... I have done: a function: function highlight(id){ document.getElementById("mynode-"+id).select(); } However, this doesn't seem to do anything... Not sure if thats the correct way :/ – Alias Oct 16 '12 at 13:07
  • @Alias i'm not sure what you mean by selected. do you want some text to be highlighted? – jbabey Oct 16 '12 at 13:09
  • Yeah, basically when they click the button the div pops up (as it does now), however the text is already highlighted so all they have to do is press Ctrl + C to copy it :) – Alias Oct 16 '12 at 13:20
  • @Alias where is the text located? in an `input type="text"`? what is that element's ID? – jbabey Oct 16 '12 at 13:25
  • Well a div is produced with the id='mynode-(counter)' at the end of each row, so the image is clicked it loads the popup based on which row was clicked, so the first row would trigger
    Content
    So just the content inside of the div that's all.
    – Alias Oct 16 '12 at 13:36
  • see [this question](http://stackoverflow.com/questions/1173194/select-all-div-text-with-single-mouse-click), just put the code inside `popup` instead of an onclick handler. – jbabey Oct 16 '12 at 13:40