How can I execute a JavaScript function if select is creating rows/options?
<form:select path="field" multiple="false" size="8" cssClass="reg-selectField" onOptionsCreated="runThisJsFunction()">
<form:options items="${field}" itemValue="id" itemLabel="name" cssClass="input-select" disabled="false"/>
</form:select>
Something like what I've added onOptionsCreated="runThisJsFunction()" on the code above.
I don't think that we have a particular event which is triggered when options are loaded.You can do the same thing in document.ready jQuery function or in JavaScript something like
function options_loaded() {
var e = document.getElementByNames('field')[0];
if(e.options.length == 0){
alert("No options loaded");
}
}
document.addEventListener("DOMContentLoaded", options_loaded, false);
in jQuery
$(function(){
var optionsCount = $('[name="field"] option').length;
if (optionsCount == 0){
alert("No options are loaded");
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With