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

3 Answers 3

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?

Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

Server side language isn't an option :/
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.