Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get <p:selectOneMenu> value using JQuery

How I can get select component value using Jquery or javascript

MyJSF code below

<h:form>
      <p:selectOneMenu style="width:150px" id="id" onchange="onCall()">
              <f:selectItem itemLabel="Select" itemValue=""></f:selectItem>
              <f:selectItem itemLabel="Other" itemValue="Other"></f:selectItem>
       </p:selectOneMenu>
       <p:selectBooleanCheckbox id="flag"/>
       <p:inputText id="name" value="#{mybean.value}/>
 </h:form>

Please help me to solve this issue

like image 511
JSF Learner Avatar asked Jan 23 '14 13:01

JSF Learner


1 Answers

As Primefaces provides a Javascript API for its components, you can access it through the widgetVar

xhtml

<p:selectOneMenu widgetVar="selectWV">               
</p:selectOneMenu>

JS

PF('selectWV').getSelectedValue();//gets the value
PF('selectWV').getSelectedLabel();//gets the label
like image 179
Hatem Alimam Avatar answered Nov 02 '22 05:11

Hatem Alimam