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

I have two pages; page1 and page2. page1 holds a form while page2 has some images. I want to enter a se

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745154094a4614013.html

相关推荐

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

    I have two pages; page1 and page2. page1 holds a form while page2 has some images. I want to enter a se

    2小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信