sarah sarah - 20 days ago 7
Javascript Question

read teaxt area value on next page. storing values for the next page

I have a textarea and i want to get the input from it and onthe next page use the input.

I guess i need to store the input value somwhere to be used on the second page. Is there a way to do it without plugins? if not, how else can i do this? Please provide examples if possible.

<textarea id="map" rows="3" cols="43"></textarea>
<button type="button" onClick="save()">Save</button>

function save() { //code to save info to be used on next page}

Answer

You can improve the behavior doing client-side checking with localStorage, or you can use sessionStorage

Example:

ON PAGE 1 do this:

 <textarea id="map" rows="3" cols="43"></textarea>
 <button type="button" onClick="save()">Save</button>

 <script type = "text/javascript">

 function save() { 

 var someText = document.getElementById("map").value;
 sessionStorage.setItem('myvar', someText);
 window.location.href = "page2.html";
 }

NOW on PAGE 2 (page2.html) to get the value simply do this:

 <script>
 var data = sessionStorage.getItem('myvar');

  alert(data);

 </script>

Basically whatever you type in textarea (on page 1) will be available in Page 2.

Comments