表单执行操作并调用值 [英] Form to perform action and passover the values

查看:111
本文介绍了表单执行操作并调用值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我基本上有一个表单,有两个文本框,将数据发送回谷歌电子表格,因为我已将表格附加到谷歌表格,如果你知道如何做到这一点然后它确定,如果不是你可以在这里查看 http://www.morningcopy。 com.au/tutorials/how-to-style-google-forms/lets 打电话给他们,

Hi i basically have a form that has a two textboxes which will send the data back to the google spreadsheet, as i have attached my form to the google form, if u know how to do this then its ok, if not u can take a look here http://www.morningcopy.com.au/tutorials/how-to-style-google-forms/lets call them,

<form action="LINK TO GOOGLE SPREAD SHEET LINK" method="post">
<input type="text" id="tb1" name="tb1"/>
<input type="text" id="tb2" name="tb2"/>
<input type="submit" value="submit"/>
</form>

所以我的问题是一旦数据提交我想让textbox2.value传递过来到下一页我们称之为page2.html,所以之前的tb2.value被传递给page2.html textbox1.value。我也知道如何导航到下一页,因此问题不在于如何从tb2获取值并同时提交表单。 TKS一直在努力完成这项工作。

So my question is once the data is submitted I want to get the textbox2.value to be passed over to the next page lets call it page2.html, so the previous tb2.value is passed over to page2.html textbox1.value. I also know how to navigate to the next page so that is not the issue the issue is how to get the value from tb2 and also submit the form at the same time. TKS been struggling to get this done.

<form action="LINK TO GOOGLE SPREAD SHEET LINK" method="post">
<input type="text" id="tb1" name="tb1"/>
<input type="text" id="tb2" name="tb2"/>
<input type="submit" value="submit"/>


</form>

SO I HAVE MODIFIED TO LOOK AS BELOW 
For the first page is this its name is Testhtml.html


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>TEsthtml.html</title>
    </head>

    <body>

    <iframe name="response_iframe" id="hidden_iframe" style="display:none;" onload="if(submitted){window.location='simple.html';}"></iframe>
    <form action="https://docs.google.com/spreadsheet/formResponse?formkey=dDN5RE9ueU9HRGdQYzlJYWhrRUY1UEE6MQ&ifq" target="response_iframe" onSubmit="submitted=true;" method="POST">
    <label  for="entry_0">Type ur name</label>
    <input type="text" name="entry.0.single" value=""  id="entry_0">
    <br> 
    <label  for="entry_1">ur pets name
    </label>
    <label  for="entry_1">type something</label>
    <input type="text" name="entry.1.single" value=""  id="entry_1">
    <br>
    <input type="submit" name="submit" value="Submit">
    <script type="text/javascript">
    $(document).ready(function () {
        $('commentForm').submit(function () {
            var tb2_val = $('input#entry_1', $(this)).val();
            // do something with tb2_val
    localStorage.setItem('hpnumber', tb2_val);
            // return false; // uncommenting this will prevent the submit action
        });
    });

    </script>
    </form>
    </body>
    </html>

第二页是它的名字是simple.html

THE SECOND PAGE IS THIS its name is simple.html

 <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Simple HTML</title>
    <script type="text/javascript">
    $(document).ready(function () {
        var thevalue = localStorage.getItem("hpnumber")
        $('form').find('input#tb1').val(thevalue);
    });

    </script>
    </head>

    <body>
    <script type="text/javascript">
    $(document).ready(function () {
        var thevalue = localStorage.getItem("hpnumber")
        $('form').find('input#tb1').val(thevalue);
    });

    </script>
    <input id="tb1" name="tb1" type="text"/>


    </body>
    </html>

但数据能够提交时仍然无效,而simple.html正在打开第二页将文本框值设置为空白...请帮助此tks。顺便说一下,只要你按下提交按钮,你就可以在google电子表格中更新数据,电子表格在这里公开了。 https://docs.google.com/spreadsheet/ccc?key=0AqUqEITRLZjYdDN5RE9ueU9HRGdQYzlJYWhrRUY1UEE

but still not working while the data is able to submit and the second page the simple.html is opening up with the textbox value set to nothing just blank..please help with this tks. BTW u can c that the data is being update in the google spreadsheet whenever u press submit button, the spreadsheet is made public here you go.. https://docs.google.com/spreadsheet/ccc?key=0AqUqEITRLZjYdDN5RE9ueU9HRGdQYzlJYWhrRUY1UEE

推荐答案

要在提交时获取表单值,只需使用

To get the form values on submit, just use

$(document).ready(function () {
    $('form').submit(function () {
        var tb2_val = $('input#tb2', $(this)).val();
        // do something with tb2_val

        // return false; // uncommenting this will prevent the submit action
    });
});

至于在页面之间传递值,你必须确定如何处理( cookies,url参数,存储到db /从db检索,html5本地存储等)。确定方法后,获取值并执行

As far as passing values between pages, you'll have to determine how you'll handle that (cookies, url parameters, store to db/retrieve from db, html5 local storage, etc). Once you determine your method, grab the value and do

$(document).ready(function () {
    var thevalue = ///
    $('form').find('input#tb1').val(thevalue);
});

这篇关于表单执行操作并调用值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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