简体   繁体   English

如何将一个页面的文本框值传递到另一个页面的文本框?

[英]How to pass textbox value from a page into a textbox in another page?

I try to pass the textbox value from a page to another page. 我尝试将文本框值从一个页面传递到另一个页面。 I try to pass that text box but failed I use javascript for doing that. 我尝试通过该文本框,但是我使用JavaScript失败了。 I have to try to change my code properly but still not work the error is the data that passing to the text box is multiple. 我必须尝试正确更改代码,但仍然无法正常工作,错误是传递给文本框的数据是多个。

this is my code 1st-page code 这是我的代码第一页代码

  function myFunction() { var inputTest = document.getElementById('tanggal2').value; var inputTest1 = document.getElementById('dt').value; localStorage.setItem( 'objectToPass', inputTest ); localStorage.setItem( 'objectToPass1', inputTest1 ); if (inputTest=="") { window.open('report_pengambilan_singgle.html','','height=650,width=1200'); } else { window.open('report_pengambilan_singgle1.html','','height=650,width=1200'); } } 
 <input type="text" id="dt" type="text" name="dt" maxlength="1" size="23" readonly="readonly" style="visibility:hidden" /> <input type="text" id="tanggal2" type="text" name="tanggal2" maxlength="1" size="23" readonly="readonly" style="visibility:hidden" /> <label onclick="myFunction();" >a</label> 

and this my 2nd-page code 这是我的第二页代码

  var inputTest = localStorage.getItem('objectToPass'); var inputTest1 = localStorage.getItem('objectToPass1'); var displayData = inputTest; var displayData = inputTest1; document.getElementById("datepicker1").value=inputTest; document.getElementById("datepicker2").value=inputTest; document.getElementById("datepicker3").value=inputTest; localStorage.removeItem( 'objectToPass1' ); // Clear the localStorage localStorage.removeItem( 'objectToPass' ); // Clear the localStorage 

you have textbox which have hidden and not any value define 您有隐藏的textbox ,没有任何值定义

so first set any value in textbox and create textbox in another page before your <script> start 因此,首先在<script>开始之前在textbox设置任何值,然后在另一个页面中创建textbox

like 喜欢

<input type="text" id="datepicker1" value="">
<input type="text" id="datepicker2" value="">
<input type="text" id="datepicker3" value="">

Try this way... 试试这个...

test.html 的test.html

<script>function myFunction() {

var inputTest = document.getElementById('tanggal2').value;
var inputTest1 = document.getElementById('dt').value;

if (inputTest=="") {
                    window.open('report_pengambilan_singgle.html','','height=650,width=1200');
            }   
            else {

                    window.open('test1.html?name=' + inputTest1,'','height=650,width=1200');
            }

}
</script>
<input type="text" id="dt" type="text" name="dt"  size="23"  />
<input type="text" id="tanggal2" type="text" name="tanggal2"  size="23"  />
<button onclick="myFunction();" >a</button> 

test1.html test1.html

<script>window.onload = function () {
var url = document.location.href,
    params = url.split('?')[1].split('&'),
    data = {}, tmp;
for (var i = 0, l = params.length; i < l; i++) {
     tmp = params[i].split('=');
     data[tmp[0]] = tmp[1];
}
document.getElementById("datepicker1").value = data.name;
}
</script>
<input type="text" id="datepicker1" type="text" name="datepicker1"  size="23"  />

i Hope working for u... 我希望为你工作...

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

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