user1202360
user1202360

Reputation: 21

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:

<form name="form1">
<select name="menu" onChange="location=document.form1.menu.options[document.form1.menu.selectedIndex].value;">
<option value=''></option>
<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>
</select>
</form>

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?

Upvotes: 1

Views: 3968

Answers (1)

JimmyBanks
JimmyBanks

Reputation: 4728

add in selected="selected" anywhere within the option tag

whichever one this is added to will remain selected, simply change your php/perl/python (whatever language) to add this code to one which is selected by the user through your $_POST value

for example if you wanted the last option to be selected, this would be the html code

<option selected="selected" value="<?php the_permalink() ?>?product_order=id">Recently Added</option>

Upvotes: 1

Related Questions