2

Ok so I will say I'm just a beginner so this may be a basic question.

But say I have some inputs on one page:

<input type="text" id="x" /> <br>
<input type="text" id="y" /> <br>
<input type="text" id="z" /> <br>

And I have a script on the other:

function aaa(){
var SimpleSum = x*y+z;
alert(SimpleSum);

}

Now is there anyway to save the variables from the form on one page so that I can use them on the other page.

nickfogle
  • 146
  • 1
  • 9
  • 1
    yes there are many ways. you could pass them to the other page "by url parameters" (make them part of the url so when the user opens the other page, it receives them), or you could save the values in localStorage or other storage available. The question is a little broad since you are not showing an attempt or an actual problem with code. Google both of these and come back with code if still not working or unclear. – Zig Mandel May 02 '15 at 02:24

1 Answers1

1
  1. You can save it to localStorage using something like the following.

Store variable:

localStorage.setItem("SimpleSum", "value");

Retrieve the variable:

document.getElementById("result").innerHTML = localStorage.getItem("SimpleSum");

See more here: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage. *Note that local storage isn't supported by all browsers.

  1. You could also pass that variable using a url parameter. Then subsequently use javascript regex to parse that parameter. This has been answered in depth with examples here:

Change URL parameters

Community
  • 1
  • 1
nickfogle
  • 146
  • 1
  • 9