开发者

I need help passing data to an modal popup iframe from a dynamically generated table

I am using php to dynamically generate a table of information from a mysql database. Each row of data has an edit button. When I click edit, I want to popup a modal iframe containing a form for editing the data. I have the table and the popup working, however, I cannot find a way to send the id of the data row so that I can 开发者_StackOverflow社区query the database and autofill the form.

I got the code for the popup iframe from here:

Any help is appreciated, but please bear in mind that I am new to js and ajax.

EDIT: sorry, wrong link. correct link is http://deseloper.org/read/2009/10/jquery-simple-modal-window/


This depends on where the data of your iFrame is coming from. If the src of your iFrame paints to a completely different domain, there is nothing you can do because of the browser's Same-origin policy: http://en.wikipedia.org/wiki/Same_origin_policy

If it comes from the same origin/domain, you might be able to use the method mentioned in this question: Pass value to iframe from a window

From what it sounds like you're doing, you probably don't even need the iframe. Modal windows in web pages are created with some CSS trickery and absolute positioning so that anything that is contained within the content node of the container displays in the window.

By using some Javascript code, you can pass in a callback function to the modal window constructor that gets executed when the "OK"/"close"/"w/e" button is clicked.

For example:

function createModalWindow(){
    var sendDataToServer = function() { /* do stuff */ );

    new modalWindow({
        onClose: sendDataToServer
    });
}

So the above code has you creating an anonymous function and passing it as the callback that is called when modalWindow.onClose is called.

Also, if you are new to javascript, the above method works because functions are essentially treated like objects in the JS, so they can be passed around as parameters to other functions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜