开发者

submit multiple forms

I'm having multiple iframes in one page each one cont开发者_如何学Cains a form , and i put the submit button outside the iframes , and when user press on submit all forms should be submited and then the page should be closed , any one can help me in this?

this function called onclick on submit button

function Save_Close()
     {
        if (window.frames.intake_pat_info_iframe && window.frames.intake_pat_info_iframe._Submit('Update')) {
            window.frames.intake_pat_info_iframe._Submit('Update');

        }
        if (window.frames.intake_job_info_iframe && window.frames.intake_job_info_iframe._Submit('Update')) {
            window.frames.intake_job_info_iframe._Submit('Update');

        }
        if (window.frames.intake_spine_his_iframe && window.frames.intake_spine_his_iframe._Submit('Update')) {
            window.frames.intake_spine_his_iframe._Submit('Update');

        }
        if (window.frames.intake_past_med_history_iframe && window.frames.intake_past_med_history_iframe._Submit('Update')) {
            window.frames.intake_past_med_history_iframe._Submit('Update');
    }

....

<input type="button" id="" name="" value="Save & Close" onclick="Save_Close()"/>

thnx


As long as you can use Javascript and your iframes are all being served from the same server, it's not that hard. A completely pure inline JS approach looks like (this is using ASP.NET for the server-side stuff but the important bit is the onclick() handler in the button)

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
  <title>IFRAME form submit demo</title>
</head>
<body>
  <iframe name="iframe1" src="my_form.aspx"></iframe>
  <iframe name="iframe2" src="my_form.aspx"></iframe>
  <iframe name="iframe3" src="my_form.aspx"></iframe>
  <iframe name="iframe4" src="my_form.aspx"></iframe>
  <input type="submit" value="Submit All IFrames" 
           onclick="for(var i = 0; i < frames.length; i++) { frames[i].document.forms[0].submitButton.click(); }" />
</body>
</html>

EDIT: now explicitly calls form.submitButton.click() instead of form.submit() to invoke functions bound to submit button's Click handler.


This is not easy to achieve.

Each IFrame is a different document, and a submit button will only work on a single form, the one that is belongs to.

The get this to work, you will need to collect you data from all IFrames using javascript to populate one or more hidden fields on the form that the submit button is on.

If the different IFrames are on different domains however, this will not be possible due to the same origin security policy.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜