How to pass <select> option from page1 to page2 using JavaScript? -
i want pass page1.html selected value next page2.html page1.html :
<form action="product.php" method="post"> <select name="option"> <option value="product">product</option> <option value="event">event</option> <option value="organization">organization</option> <option value="movie">movie</option> <option value="book">book</option> <option value="review">review</option> <option value="recipe">recipe</option> </select> <input type="submit" name="submit" value="go"/> </form>
how can create var recieve selected option on page2.html using post method?
thanks, ofer
an elegant way of doing using localstorage
have minor change in html & put snippet in js
file
html
<form onsubmit = "somefunction()" > // function executed on submit //rest of code </form>
js
function somefunction(){ if(typeof(storage) !== "undefined") { // checking storage supported localstorage.setitem("yourkey", "yourvalue"); } else { // take necessary action if not supported } }
in second page
var _mystoreditem = localstorage.getitem("yourkey");
beside using localstorage, can use
for example assume url
http://www.mypage.com/product.php?mydate=somedate
and in second page
var myvar = window.location.search.
if there multiple query parameter have parse query string required parameter. require form method ="get"
.since using post
may not relevant you.
Comments
Post a Comment