简体   繁体   English

从一个HTML表单中提取数据并在另一页面中显示

[英]Extract data from one html form and display it another page

I am building a page to conduct survey. 我正在建立一个页面进行调查。 I have an HTML page wherein the surveyor enters the questions and choices to the corresponding questions. 我有一个HTML页面,调查员在其中输入问题和对相应问题的选择。 The page contains two buttons, one is the preview survey and other submit. 该页面包含两个按钮,一个是预览调查,另一个是提交。 What I want is that when the user clicks on "preview survey"button, the user should be directed to another page which only displays the questions and the choices entered by the surveyor. 我想要的是,当用户单击“预览调查”按钮时,应该将用户定向到另一个页面,该页面仅显示问题和调查员输入的选择。 How do I do this functionality? 如何执行此功能?

Basically, it is extracting data from an HTML form and displaying it in another page. 基本上,它是从HTML表单中提取数据并将其显示在另一个页面中。 Something like this: http://www.surveymonkey.com/s.aspx?PREVIEW_MODE=DO_NOT_USE_THIS_LINK_FOR_COLLECTION&sm=3sP%2fucxKJsI57gtum0mLXhMpuD4LqWiUaSkI8eVytnk%3d 像这样的东西: http : //www.surveymonkey.com/s.aspx? PREVIEW_MODE=DO_NOT_USE_THIS_LINK_FOR_COLLECTION&sm=3sP%2fucxKJsI57gtum0mLXhMpuD4LqWiUaSkI8eVytnk%3d

There are tons of tutorials on how to handle form input in web applications on the web. 关于如何处理Web上Web应用程序中表单输入的大量教程 Just pick one for your programming language of choice. 只需选择一种适合您的编程语言即可。

You have a few options: 您有几种选择:

1. Open up the preview in an overlay-dialog 1.在覆盖对话框中打开预览

You can use stuff like Jquery UI dialog for that, or any other library like Twitter Bootstrap or Wijmo . 您可以使用诸如Jquery UI对话框之类的东西,或诸如Twitter BootstrapWijmo之类的任何其他库。 This way you don't need to direct to another page and do not have to juggle with variables (you do need some javascript to fetch the options and insert them in the dialog 这样,您就无需定向到另一个页面,也不必弄乱变量(您确实需要一些JavaScript来获取选项并将其插入对话框中

2. Post a form to the other page 2.将表单发布到另一页

This will also, most probably, needs some javascript. 这也很可能需要一些javascript。 But assuming you have the survey in a form already this won't be that difficult. 但是,假设您已经以某种形式进行调查,就不会那么困难了。 You can, example given, use the jQuery.serialize() function to serialize form input and send it over to some other page. 您可以使用给出的示例,使用jQuery.serialize()函数来序列化表单输入并将其发送到其他页面。 You can either construct an Ajax/XHR request, or send it directly to a popup window (needs you to alter the action type though when you want to finally submit the form). 您可以构造Ajax / XHR请求,也可以将其直接发送到弹出窗口(尽管您希望最终提交表单,但您需要更改操作类型)。 Example here 这里的例子

3. Open up a popup and let it directly speak to it's parent window 3.打开一个弹出窗口,让它直接与其父窗口对话

With the window.parent property you can talk to the window/page that opened the popup. 使用window.parent属性,您可以与打开弹出窗口的窗口/页面对话。 Than you can read out properties, like form values, and use them in the pop-up. 比起您,您可以读出属性,例如表单值,然后在弹出窗口中使用它们。 It works pretty much like this: 它的工作原理大致如下:

survey_page.html survey_page.html

<script type="text/javascript">
    var popup = window.open('popup.html', 'width=300, height=200');
    if(window.focus) popup.focus();
    return false;
</script>
<form name="testform" id="testform">  
    <input type="text" name="atextfield" value="" />
</form>
<a href="#" class="popup" onclick="open_popup()">Open popup</a>

popup.html popup.html

<script type="text/javascript">
    function alertParentValue() {
        alert(window.opener.document.forms['testform'].atextfield.value);
    }
</script>
<a href="#" onclick="return alertParentValue();">Also click me!</a>

If you click the open pop-up link and then click on the other link, you'll be alerted the value which you filled in in the text field. 如果您单击打开的弹出链接,然后单击另一个链接,则会提示您在文本字段中填写的值。

Other options are most probably available, choose whichever suits you! 其他选项很可能可用,请选择适合您的一个!

在预览按钮上,您只能使用弹出式窗口,因为此页面无法重定向到其他页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM