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? Link to comment https://forums.phpfreaks.com/topic/118716-combining-2-scripts/ Share on other sites More sharing options...
DBookatay Posted August 8, 2008 Author Share Posted August 8, 2008 Anyone have any ideas? Link to comment https://forums.phpfreaks.com/topic/118716-combining-2-scripts/#findComment-611318 Share on other sites More sharing options...
haku Posted August 8, 2008 Share Posted August 8, 2008 java != javascript. Link to comment https://forums.phpfreaks.com/topic/118716-combining-2-scripts/#findComment-611351 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. Link to comment https://forums.phpfreaks.com/topic/118716-combining-2-scripts/#findComment-611482 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? Link to comment https://forums.phpfreaks.com/topic/118716-combining-2-scripts/#findComment-612092 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; } } Link to comment https://forums.phpfreaks.com/topic/118716-combining-2-scripts/#findComment-612597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.