1

I'm quite new to JavaScript andI'm trying to do the following:

I've two webpages Page1.html and Page2.html On Page1.html I've one textbox and a button. After a user puts in some text in the textbox and clicks the button, I want Page2.html be opened and the text of the textbox appearing in the body of the newly opened Page2.html as follows:

"You wrote" + "[text from the textbox on Page1.html]"

I've tried the getElementById thing. But because of my very obvious green horns, I am missing something very basic in here. Can anybody please elabourate as to how I should proceed?

Sachin Borkar
  • 65
  • 1
  • 5

1 Answers1

0

The web is stateless by nature. So when you request Page1.html it will get loaded as though it had never been loaded before, a blank slate.

In order to pass information between two pages, you have to include that information in the request. Normally this is done via a web server that embeds information from one request into another.

Since you are doing this purely from JavaScript, you would probably have to pass the information via the Query String.

When you navigate from Page1.html to Page2.html you will need to do something like this:

windows.location = 'Page2.html?variableName=somevalue';

When Page2.html loads up, you will need to inpsect those values and extract the information you need.

Here is an example of doing just that: How can I get query string values in JavaScript?

Hopefully this will get you started in the right direction, but I think you are ready to start dabbling in a good server side technology like ASP.Net, PHP, Ruby on Rails, or Node.js

Community
  • 1
  • 1
Josh
  • 44,706
  • 7
  • 102
  • 124