2

I have two pages; page1 and page2. page1 holds a form while page2 has some images. I want to enter a sentence into the form on page1 and get the value of that text box on page2.

the form on page1

<form name="input" action="page2.html" method="get">
    <input type="text" name="textbox" id="textbox">
    <input type="submit" value="Submit">
</form>

what would be the proper way to go about this?

Would I use the get method along with the action method to send the value through the url and then extract it using window.location.href then splitting the text after the ? or is there a simpler way of achieving this?

Thanks

Eric Goncalves
  • 5,253
  • 4
  • 35
  • 59

3 Answers3

2

Just send it in the query string and read it in page2, as you said.

See this to have an idea of how to read the query string parameter:

How can I get query string values in JavaScript?

Community
  • 1
  • 1
Oscar
  • 13,594
  • 8
  • 47
  • 75
2

Your way of doing this would work, although it's certainly not a good long term solution. If your site is going to get more complicated, it would be better to use a server-side language like .NET, PHP, Ruby, etc.

Justin Helgerson
  • 24,900
  • 17
  • 97
  • 124
1

If you have to get thed data using only JS, then you need to use URL. Otherwise you can use server side script like jsp.

When you use URL, make sure the text is URL-encoded before appending to the URL.

ATOzTOA
  • 34,814
  • 22
  • 96
  • 117