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...

1
  • Did you contact the developer of the widget and ask for them to support it? Commented Oct 16, 2012 at 12:24

1 Answer 1

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...
}
Sign up to request clarification or add additional context in comments.

6 Comments

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 i'm not sure what you mean by selected. do you want some text to be highlighted?
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 where is the text located? in an input type="text"? what is that element's ID?
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 <div id='mynode-1'>Content</div> So just the content inside of the div that's all.
|

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.