It works well, the problem is on my app, the selection is saved via database. But when the page is refreshed, the database data does not load. It only loads when the user makes a selection change.
On the link above, try adding “SELECTED” on of the options, then hit the “edit and click me” button, you will find that no data is loaded for that selection until you make a change.
So, you need an extra piece of scripting that can check to see if the select box is on an index value that is greater than 0, and if it is it can then trigger the same onchange event.
Give the form a unique identifier, so that the script can easily interact with it:
<form id="customerinfo" action="">
Place this script at the end of the body, just before the </body> tag.
var form = document.getElementById('customerinfo'),
select = form.elements.customers;
if (select.selectedIndex > 0) {
select.onchange();
}