Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass values from one html page to another html page using javascript

In first page im getting value in textbox i need to pass it to another page which is divided into 2 frames. I need to display that value in first frame's html page. Please provide me a simple example. I tried with window.document.getElementById("inputbox1").value but im unable to get the value.

Please provide me a simple example.

like image 552
user1825788 Avatar asked Nov 20 '12 09:11

user1825788


1 Answers

I would go with localStorage, as @MicrosoftGoogle propose, but is not well supported yet, you can use pure javascript to achieve this. You will have something like this on your form page:

<form action="param-received.html" method="GET">
   <input type="text" id="foo" name="foo">
   <input type="submit" value="Send" name="submit" id="submit">
</form>

Once you click on Send button,you will be redirect to /param-received.html?foo=hola&submit=Send.

  • location.search attribute contains the chain of parameters.
  • ? concatenates the URL and the string of parameters.
  • & separates multiple parameters.
  • = assigns a value to the variable.

Here is the complete code to process data sent on param-received.html:

<script language="JavaScript">
  function processForm()
  {
    var parameters = location.search.substring(1).split("&");
    var temp = parameters[0].split("=");
    l = unescape(temp[1]);
    alert(l); //Dialog with the text you put on the textbox
  }
  processForm();
</script>
like image 63
Tom Sarduy Avatar answered Oct 03 '22 08:10

Tom Sarduy