Javascript 在提交按钮上打开一个弹出窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8986658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 08:18:03  来源:igfitidea点击:

Open a popup window on submit button

javascriptjqueryajaxjsp

提问by Tom

I have one form in JSP. I have some input fields in that page, when user types his values then he clicks submit so that values will be inserted into the database.

我在 JSP 中有一种形式。我在该页面中有一些输入字段,当用户键入他的值时,他单击提交,以便将值插入到数据库中。

But my purpose is that when user clicks submit button then one new popup window will be generated and this new popup window will carry those values at the time of inserted values in parent window. Ex: first page: Insert.jsp and popup window: Verifyinsert.jsp. In Insert.jsp page 3 input fields are present such as roll number, student name, address. User will enter these 3 fields first on Insert.jsp page and then user will click submit on Insert.jsp page, then one new popup window(Verifyinsert.jsp) will be generated carrying values when user just has typed in Insert.jsp and in that Verifyinsert.jsp page, submit button is present and if user clicks submit then records will be inserted into database and if cancel button will be clicked on Verifyinsert.jsp then that popup window will be simply disappeared. How to do it?

但我的目的是,当用户点击提交按钮时,将生成一个新的弹出窗口,这个新的弹出窗口将在父窗口中插入值时携带这些值。例如:第一页:Insert.jsp 和弹出窗口:Verifyinsert.jsp。在 Insert.jsp 页面中,存在 3 个输入字段,例如卷号、学生姓名、地址。用户首先在Insert.jsp页面输入这3个字段,然后用户在Insert.jsp页面点击提交,然后当用户刚刚输入Insert.jsp并在在Verifyinsert.jsp 页面中,存在提交按钮,如果用户单击提交,则记录将插入到数据库中,如果在Verifyinsert.jsp 上单击取消按钮,则该弹出窗口将直接消失。怎么做?

Any help is much appreciated.

任何帮助深表感谢。

采纳答案by Victor

Use onSubmitevent

使用onSubmit事件

<html>
    <head>
        <script type="text/javascript">
            function greeting(){
                alert("Welcome " + document.forms["frm1"]["fname"].value + "!")
            }
        </script>
    </head>
    <body>

        What is your name?<br />
        <form name="frm1" action="submit.htm" onsubmit="greeting()">
            <input type="text" name="fname" />
            <input type="submit" value="Submit" />
        </form>

    </body>
</html> 

回答by demalexx

Are you asking how to show popup window? Should it be js popup, with no page reload, or separate browser tab? For former we use jqModal library, examples. When user clicks on Submit button you need to display that popoup. When user clicks on Send button on that popup you need to get all values and send them to the server. There are a couple of way to do that too :)

你问如何显示弹出窗口?它应该是 js 弹出窗口,没有页面重新加载,还是单独的浏览器选项卡?对于前者,我们使用 jqModal 库,examples。当用户单击提交按钮时,您需要显示该弹出窗口。当用户单击该弹出窗口上的发送按钮时,您需要获取所有值并将它们发送到服务器。也有几种方法可以做到这一点:)

回答by Abhi

Open a popup window in the submit of your Insert.jsp using

在您的 Insert.jsp 的提交中打开一个弹出窗口

   window.open("../insert.jsp?param1=xx&&pram2=cc")

you can send the parameters as append to the url of new window like above.

您可以像上面一样将参数作为附加到新窗口的 url 发送。

In the submit of Verifyinsert.jsp , you can call a parent page java script usign

在Verifyinsert.jsp的提交中,可以调用父页面java脚本使用

window.opener.saveValue() 

which is a javscript function in your parent page to save values to database . Close your popup after saving .

这是父页面中的一个 javscript 函数,用于将值保存到数据库。保存后关闭弹出窗口。