在弹出窗口中提交表单,然后关闭弹出窗口 [英] Submit a form in a popup, and then close the popup

查看:950
本文介绍了在弹出窗口中提交表单,然后关闭弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我开始使用它时,这似乎很微不足道!我的目标是这样的:




  • 当用户点击一个按钮时,在新窗口中打开一个表单。

  • 表单提交后,关闭弹出窗口并返回到原始页面。相反的顺序也没问题 - 也就是说,如果弹出窗口已关闭,然后表单提交,我没关系。



这样做:

 < form action =/ system / wpacertmethod =postenctype =multipart / form -dataonsubmit =return closeSelf()name =certform> 
< div>证书1:< input type =filename =cert1/>< / div>
< div>证书2:< input type =filename =cert2/>< / div>
< div>证书3:< input type =filename =cert3/>< / div>

< div>< input type =submitvalue =Upload/>< / div>
< / form>

,Javascript看起来像这样:

 < script type =text / javascript> 
函数closeSelf(){
self.close();
返回true;
}
< / script>

这似乎在IE8和Chrome上运行良好;但Firefox拒绝提交表单;它只是关闭弹出窗口。我可能会做错什么?



编辑:



忘记发布代码后,打开弹出窗口。这里是:

 < div>< input type =submitvalue =Upload Certificatesonclick =popupUploadForm ()/> 





和相应的javascript:

 函数popupUploadForm(){
var newWindow = window.open('/ cert.html','name', '高度= 500,宽度= 600');
}


解决方案

我的机器在IE和FF上工作。

  function closeSelf(){
//做某事

if(条件满足){
alert(条件满意,提交表格。);
document.forms ['certform']。submit();
window.close();
} else {
alert(条件不满意,返回窗体);



$ b
< div>证书1:< input type =filename =cert1/>< / div>
< div>证书2:< input type =filename =cert2/>< / div>
< div>证书3:< input type =filename =cert3/>< / div>

//将提交按钮更改为普通按钮
< div>< input type =buttonvalue =Uploadonclick =closeSelf();/><< ; / DIV>
< / form>


This seemed so trivial when I started off with it! My objective is this:

  • When user clicks on a button, open up a form in a new window.
  • Once the form is submitted, close the popup and return to the original page. The reverse order is fine too - i.e., I am okay if the popup is closed and then the form submits.

Here's how I'm doing this:

<form action="/system/wpacert" method="post" enctype="multipart/form-data" onsubmit="return closeSelf()" name="certform">
                <div>Certificate 1: <input type="file" name="cert1"/></div>
                <div>Certificate 2: <input type="file" name="cert2"/></div>
                <div>Certificate 3: <input type="file" name="cert3"/></div>

                <div><input type="submit" value="Upload"/></div>
            </form>

and the Javascript looks like this:

<script type="text/javascript">
function closeSelf(){
    self.close();
    return true;
}
</script>

This seems to work fine on IE8 and Chrome; but Firefox refuses to submit the form; it just closes the popup. What might I be doing wrong?

EDIT:

Had forgotten to post the code the opens the popup. Here it is:

<div><input type="submit" value="Upload Certificates" onclick="popupUploadForm()"/>

And the corresponding javascript:

function popupUploadForm(){
        var newWindow = window.open('/cert.html', 'name', 'height=500,width=600');
    }

解决方案

I have executed the code in my machine its working for IE and FF also.

function closeSelf(){
    // do something

    if(condition satisfied){
       alert("conditions satisfied, submiting the form.");
       document.forms['certform'].submit();
       window.close();
    }else{
       alert("conditions not satisfied, returning to form");    
    }
}


<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>Certificate 3: <input type="file" name="cert3"/></div>

       // change the submit button to normal button
       <div><input type="button" value="Upload"  onclick="closeSelf();"/></div>
</form>

这篇关于在弹出窗口中提交表单,然后关闭弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆