I have got the <select>
element. And if I'm choosing for something, I would like to change URL
by my value in <select>
and set selected=selected
.
Try something like this (jQuery):
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type = "text/javascript">
$(document).ready(function() {
$('#my-select').bind('change', function () {
var url = $(this).val();
if (url != '') {
window.location = url;
$('#my-select').find("option[value='"+url+"']").attr("selected", "selected");
}
return false;
});
});
</script>
<select id="my-select" name="category">
<option selected> Please select... </option>
<option value="index.php?page=category&s=something1"> something1 </option>
<option value="index.php?page=category&s=something2"> something2 </option>
</select>
URL
is changed, but attribute selected
is not set.
I searched everywhere for about an hour, but never a proper example. Excuse me for my worse English.
What is going wrong? How to solve that?