2

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
Moorthy
  • 301
  • 1
  • 13
Minervaz Mine
  • 273
  • 1
  • 3
  • 17
  • 2
    Possible duplicate of [Sharing a variable between multiple html pages](https://stackoverflow.com/questions/16264253/sharing-a-variable-between-multiple-html-pages) – Nisarg Shah Jul 29 '17 at 06:24

2 Answers2

0

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="">
Bhargav Chudasama
  • 6,928
  • 5
  • 21
  • 39
  • i have try to give value on that `textbox` and i have `textbox` in other page for get the value from the `textbox` in page 1. ok.. i get the value but.. just value from `id=tanggal2` only that i get. and it pass on all text box that i made in page 2 – Minervaz Mine Jul 29 '17 at 06:53
  • you pass value in `textbox` is same like `document.getElementById("datepicker1").value=inputTest; document.getElementById("datepicker2").value=inputTest; document.getElementById("datepicker3").value=inputTest;` so you change `document.getElementById("datepicker3").value=inputTest1;` – Bhargav Chudasama Jul 29 '17 at 06:56
  • hmmm... i dont know why. it still passing same data – Minervaz Mine Jul 29 '17 at 07:06
0

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

Moorthy
  • 301
  • 1
  • 13