简体   繁体   中英

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. 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

so first set any value in textbox and create textbox in another page before your <script> start

like

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

Try this way...

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

<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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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