I am updating a multi select box using ajax with prototype:
new Ajax.Updater(selectbox, someurl,{
method:'post',
parameters: "data=" + result,
onFailure: function(){ alert('ajax updater error'); }
});
The updater works pretty well and the select box is updated with options returned by the ajax call. The only problem is that the very top option is being automaticly selected in IE.
I was trying to manually deselect it by putting
document.getElementById(selectbox).options[0].selected = false;
right after the Ajax.Updater() function and inside the onSuccess: {} clause but it was initialised before the checkbox was updated so the only way from here was to set a delay but I’m wondering if there’s another way to do this?
Also adding the attribute selected="false" to every option does not solve the problem as then the last option is being selected automaticly 🙁
Add a first field with empty value (or something your program understands as “not a value in the expected domain”) and select it. The HTML select field MUST have a field selected all the time (right?)
EDIT The w3c specs states that:
So, the behavior must be controlled by the application, as each browser can choose a different one by default. But eventually, one of them will be chosen. Usually , when it has multiple attribute defined, it selects none but… specs state nothing about that, so the empty option could work as well (to be sure).