I would like to have all select/options automatically sorted client
side. Tried this:
<script>
jQuery(document).ready(function(){
jQuery("select").each(function(){
var i = jQuery(this).attr('selectedIndex');
jQuery(this).html(jQuery(this).children("option").sort(function
(a,b) {
return (a.text == b.text)?0:((a.text < b.text)?-1:1);
}));
alert(jQuery(this).attr('id')+i);
if(i<0 || i==null)
jQuery(this).children("option:first").attr("selected","selected");
});
});
</script>
<form>
<select id="A">
<option>C</option>
<option selected="selected">B</option>
<option>A</option>
</select>
<select id="C">
<option>Z</option>
<option>Y</option>
<option>X</option>
<option>T</option>
</select>
</form>
The sorting works but while in the first case B is correctly selected.
In the second case Z is selected instead of T.
This is because if(i<0 || i==null) is always false while it should be
true for the second select.
Any idea of how to fix this?
Massimo
--
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en.