表单执行操作并调用值

时间:2011-12-20 15:32:51

标签: javascript jquery html google-docs

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

<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。值。我也知道如何导航到下一页,因此问题不在于如何从tb2获取值并同时提交表单。 TKS一直在努力完成这项工作。

<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

 <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

1 个答案:

答案 0 :(得分:0)

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

即可
$(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
    });
});

就在页面之间传递值而言,您必须确定如何处理(cookie,url参数,存储到数据库/从db检索,html5本地存储等)。确定方法后,抓住值并执行

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