DBookatay Posted August 8, 2008 Share Posted August 8, 2008 Hello, I have a script that uses a pulldown menu to send the user to the selected page. I use this script to "filter" items on the page: function faqRedirect(selectBox) { var faqURL = selectBox.options[selectBox.selectedIndex].value if (faqURL != "") { if (faqURL.substr(0, 4) != "http") faqURL = "../" + faqURL location.href = faqURL } } <select id="filter" name="filter" onChange="faqRedirect(this)"> <option value="search.php?cat=001&filter=yearDESC">Year: Newest First</option> <option value="search.php?cat=001&filter=yearASC">Year: Oldest First</option> <option value="search.php?cat=001&filter=priceDESC">Price: Highest First</option> <option value="search.php?cat=001&filter=priceASC">Price: Lowest First</option> <option value="search.php?cat=001&filter=milesASC">Mileage: Lowest First</option> <option value="search.php?cat=001&filter=milesDESC">Mileage: Highest First</option> </select> Question is: how do I modify the current java section of the script to write a cookie to remember the users selection the next time the page loads? Quote Link to comment Share on other sites More sharing options...
DBookatay Posted August 8, 2008 Author Share Posted August 8, 2008 Anyone have any ideas? Quote Link to comment Share on other sites More sharing options...
haku Posted August 8, 2008 Share Posted August 8, 2008 java != javascript. Quote Link to comment Share on other sites More sharing options...
peddel Posted August 8, 2008 Share Posted August 8, 2008 java != javascript. if u want to remember it in a cookie i suggest transferring the data to php, then u can choose to store it as cookie easy. Quote Link to comment Share on other sites More sharing options...
DBookatay Posted August 9, 2008 Author Share Posted August 9, 2008 I do use PHP, the question is how do I write the script using a drop down menu? Quote Link to comment Share on other sites More sharing options...
jacksonmj Posted August 9, 2008 Share Posted August 9, 2008 Use javascript, like the code below: function faqRedirect(selectBox) { var faqURL = selectBox.options[selectBox.selectedIndex].value if (faqURL != "") { document.cookie="SelectBoxPref="+faqURL.replace(/=/g,"#EQUALS#"); if (faqURL.substr(0, 4) != "http") faqURL = "../" + faqURL location.href = faqURL } } var cookies = document.cookie.split(";"); for (var i=0;i<cookies.length;i++) { if (cookies[i].indexOf("SelectBoxPref=")==-1) continue; var selectedUrl = cookies[i].split("=")[1].replace(/#EQUALS#/g,"="); var selectOption = document.getElementById("filter").firstChild; while (true) { if (selectOption.value==selectedUrl) { selectOption.selected = true; break; } if (!selectOption.nextSibling) break; selectOption = selectOption.nextSibling; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.