I tried some of the methods suggested above. However, no one was useful to me. After looking at some information, I found a property attribute in jQuery (prop ()). And this works for me, the code is as follows:
In my JSF file, I had the following code.
<h:selectOneMenu id="asignacion" value="#{contratosBean.asignacion}"> <f:selectItems value="#{contratosController.asignaciones}" var="item" itemLabel="#{item.lblAsignacion}" itemValue="#{item.idAsignacion}" /> <f:ajax onevent="showDialog()" />
JavaScript section:
function showDialog() { if($([id='formContrato:asignacion']").prop("selected",true).val() == 'X1') { alert("function X1"); }else if($("id='formContrato:asignacion']").prop("selected",true).val() == 'X2'){alert("function X2"); }else{alert("Other function");} }
source share