HTML Drop-down menu to retain selection on page refresh?
Is there anyway to do this is pure html without java?
The current html is as follows:
<select name="menu" onChange="location=document.form1.menu.options[document.form1.menu.selectedIndex].value;">
<option value="<?php the_permalink() ?>?product_order=DESC">A-Z</option>
<option value="<?php the_permalink() ?>?product_order=ASC">Z-A</option>
<option value="<?php the_permalink() ?>">Price</option>
<option value="<?php the_permalink() ?>?product_order=id">Recently Added</option>
This works, the page reloads and the sorting is applied BUT the selection in the dropdown box returns to blank - I'd like it to display the 'active' selection?
I'm assuming we might need to use PHP for the select="selected" but I'm pretty useless when it comes to PHP so need spoon feeding.
Thanks in advance!
If you do, it would be a good idea to add a rel="canonical" tag to the page that shows the URL without the 'menuIndex' value in the query string so that search engines don't see extra URLs in your site with the same content. Good luck!
<select name="menu" onChange="location=document.form1.menu.options[document.form1.menu.selectedIndex].value + '&menuIndex=' + document.form1.menu.selectedIndex;">
Thanks for the reply but that doesn't work either, it does add the &menuIndex= to the URL but the dropdown still 'forgets' the selection.
Originally Posted by rtrethewey
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)