从弹出窗口javascript提交表单

时间:2013-01-10 07:36:22

标签: javascript jquery dom

我想提交表单弹出窗口。

Parent.html

<form class="myform" name="forms" onsubmit="return submit_form()" >

</form>
<form class="myform" name="forms" >

</form>
<form class="myform" name="forms" >

</form>

Parent.html JAVASCRIPT

<script>

function submit_form()
{

console.log(0);
return false;
}

window.onload = function(){


//attach eventListner

 document.getElementsByName("forms").addEventListner("submit",function(){

  console.log(1);

  return false;

 },false);


//IN JQUERY 


$(document).ready(function(){

  $(".myform").live("submit",function(){

    console.log(2);return false;

  });

});


};


</script>

我正在使用window.open方法打开一个新的弹出窗口,

我正在尝试从弹出窗口提交表单,如下所示......

var docs = window.opener.document ;


//first try to submit through jQuery

$(docs).find("form").eq(0).submit(); // it will work all browsers except IE8

or

docs.getElementsByTagName("form")[0].submit(); // it will work everywhere ,but on parent window the form will submitted by default (no attached events will work) 

请帮助..

感谢。

1 个答案:

答案 0 :(得分:0)

div id="divform">
            <form action="/system/wpacert" method="post" enctype="multipart/form-data" name="certform">
                <div>Certificate 1: <input type="file" name="cert1"/></div>
                <div>Certificate 2: <input type="file" name="cert2"/></div>

                <div><input type="button" value="Upload" onclick="closeSelf();"/></div>
            </form>
        </div>
        <div  id="closelink" style="display:none">
            <a href="javascript:window.close()">Click Here to Close this Page</a>
        </div>

function closeSelf(){
    document.forms['certform'].submit();
    hide(document.getElementById('divform'));
    unHide(document.getElementById('closelink'));

}