开发者

passing value from 1 .htm file to another .html file without submitting

Im having a .html page which contains a set of value, when clicking on next button it will go to second .html file. I want to display the value in first .html files into second without submitting the first form and using javasript

Im tried to store that value in a javascript global variable and tried to开发者_Python百科 get that from second html, but im not getting the values.

In first .html file , ill click on a next link that will redirect it to the second .html file

Is it a good idea to do with this cookies ?, im working for an enterprise project.


I think this would be impossible.

The only way to get data from the page is to submit it to the server and process form values or use the javascript on the client side.


You could do this by creating a link that looks like a button and adding the value from first page into the querystring of the url being linked to.

I'll draw up a quick demo in a moment.

UPDATE

Here's a quick demo of the kind of thing you'd need to do. This is using plain Javascript and would be much easier with jQuery:

http://jsfiddle.net/Mb2fM/

UPDATE 2

Here's an updated version using jQuery that correctly handles the change event and updates the querystring on the button: http://jsfiddle.net/Mb2fM/1/


You can either pass the value in the querystring and read it from there.

If you do not want to change the url, you can use localstorage or cookies. Set the localstorage/cookie right before you leave the page. On the page load of the next page read the localstorage/cookie and use the value.


I think something which might work for you and is simple, is to use hidden form fields. The first page submits the form to the second page, whose form has hidden fields to contain the data from the first page. So you can access info from the previous form and process it as necessary before submitting the final form from the second page.

Haven't done this for a long time, but looking up hidden form fields will provide you with some examples.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜