I have pages like
index.php?key=toplist&list=magic
So if om on that page for example, i want the Magic option to be marked as selected in the select menu
<select name="skill" onchange="window.location.href=this.form.skill.options[this.form.skill.selectedIndex].value">
<option value="index.php?<?=QUERY_STRING?>&list=experience">Experience </option>
<option value="index.php?<?=QUERY_STRING?>&list=magic">Magic</option>
<option value="index.php?<?=QUERY_STRING?>&list=shielding">Shielding</option>
<option value="index.php?<?=QUERY_STRING?>&list=distance">Distance</option>
<option value="index.php?<?=QUERY_STRING?>&list=fishing">Fishing</option>
</select>
Thanks
You add the selected
attribute to the option
tag. I typically do it with something like this:
$lists = array('experience', 'magic', 'shielding', 'distance', 'fishing');
foreach($lists as $list)
echo "<option value=\"index.php?$QUERY_STRING&list=$list\"" . ($list == $_GET['list'] ? " selected" : "") . ">" . ucfirst($list) . "</option>"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With