I have the following javascript in-place to preselect items when a page loads. I'm using web2py and {{=fill_messages_saved}} returns an array [4, 144, 142, 143], which all correspond to values of the options I'd like to select. Unfortunately, the order is always displayed in the order generated in the portion of the html. Is there a way to load each item according to the array of values {{=fill_messages_saved}} as preselected options when a page loads? I can watch each item load individually with the alert() below, but they don't load top down.. they retain the order designated in the html. When I manually select the options, they show up correctly.
jQuery(document).ready(function(){
jQuery(function($) {
$("#fill_messages").bsmSelect({
animate: true,
highlight: true,
plugins: [$.bsmSelect.plugins.sortable(), $.bsmSelect.plugins.compatibility()]
});
});
$(window).load(function(){
$.each({{=fill_messages_saved}}.toString().split(","), function(i,e){
alert()
$("#fill_messages option[value='" + e + "']").prop('selected', true).trigger('change');
});
});
</script>
I have the following javascript in-place to preselect items when a page loads. I'm using web2py and {{=fill_messages_saved}} returns an array [4, 144, 142, 143], which all correspond to values of the options I'd like to select. Unfortunately, the order is always displayed in the order generated in the portion of the html. Is there a way to load each item according to the array of values {{=fill_messages_saved}} as preselected options when a page loads? I can watch each item load individually with the alert() below, but they don't load top down.. they retain the order designated in the html. When I manually select the options, they show up correctly. jQuery(document).ready(function(){ jQuery(function($) {
$ ("#fill_messages").bsmSelect({
animate: true,
highlight: true,
plugins: [$.bsmSelect.plugins.sortable(), $.bsmSelect.plugins.compatibility()]
});
});
$(window).load(function(){
$.each({{=fill_messages_saved}}.toString().split(","), function(i,e){
alert()
$ ("#fill_messages option[value='" + e + "']").prop('selected', true).trigger('change');
});
});
</script>