最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - getting value of input box on another page - Stack Overflow

programmeradmin2浏览0评论

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

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

Share Improve this question asked Dec 19, 2012 at 17:08 Eric GoncalvesEric Goncalves 5,3534 gold badges37 silver badges59 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 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?

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 plicated, it would be better to use a server-side language like .NET, PHP, Ruby, etc.

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.

发布评论

评论列表(0)

  1. 暂无评论