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 badges3 Answers
Reset to default 2Just 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
评论列表(0条)