-1

i have problem on sending textbox value from one html page to another html page. In first page i am sending first name and last name values.and i want to catch this value in textbox on the second page( i.e home.html).but some erroe occurs.

error is :Uncaught TypeError: Cannot set property 'value' of null

how to solve? please tell me. i know this stupid question.but please tell me guys.i don't know javascript.

this is my html code:

 <!DOCTYPE html">
 <html>
 <head>
 <script src="ttt.js"></script>
 </head>
 <body>
 <form method="get" action="home.html" name="ff">
 Firstname: <input id="f" type="text" name="firstname1">
 Lastname: <input type="text" name="lastname">
 <input type="submit">
 </form>
 </body>
 </html>

this is my home.html code:

 <!DOCTYPE html">
 <html>
 <head>

 <script src="ttt.js"></script>
 <script Language="JavaScript">
 var tttt=val();
 document.getElementById('text').value=tttt;
 </script>
 </head>
 <body>
 <form name="ff">
 <input id="text" class="text" type="text" name="MyValue" value="helloS"/> 
 </form>
 </div>
 </body>
 </html>

this is my javascript code(ttt.js)

function val(){
  var link=location.href;
  var str=link.split('?');
  var str1=str[1].split('&');
  var str11=str1[0].split('=');
  var str12=str1[1].split('=');
      var temp=str11[1]+" "+str12[1];
  return(temp);
 }

3 Answers3

0

Put your javascript at the end of your html and change document.getElementById('tr') to document.getElementById('text'). You have no element with id tr.

Raidri
  • 17,258
  • 9
  • 62
  • 65
  • Put your complete ` – Raidri Sep 25 '13 at 13:29
  • but Raidi why this problem occurs? tell me reason. – proxyserver Sep 26 '13 at 06:14
  • In the original version the javascript code was executed before the input element was put on the page, so the code couldn't find it. – Raidri Sep 26 '13 at 09:17
  • thanks.u cleard my all doubt.because this problem occurs in many program.that's y i am asking.thank u so much Raidi.. – proxyserver Sep 26 '13 at 09:24
  • Raidri can u tell me how to store value in sqlite database using html and javascript – proxyserver Sep 26 '13 at 09:29
  • That is beyond this question too and much for a comment. Take a look at [this question](http://stackoverflow.com/questions/3829818/simplest-jquery-php-ajax-and-sqlite-example) and go from there. – Raidri Sep 26 '13 at 09:34
0

please look at this question and its answers, it is demonstating how to pass value from one html page to another

link

Community
  • 1
  • 1
Tejas Vaishnav
  • 466
  • 5
  • 20
-1

You have to do getElementById('tr') when the dom is ready and ensuring that an element with the ID exists.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445