ajax - get selected value from selectOnemenu using javascript in primefaces and open a dialog box -


how can selected value of primefaces <p:selectonemenu> using javascript/jquery?

i trying way, not go inside if condition, means id of element not correct.

<h:head>      <script>          function showdialog() {              alert("insdie function");              if($('#someselect').val() == 'india') {                  dlg.show();                  alert("after function");              }              alert("outside function");          }        </script>  </h:head>  <h:body>      <h:form>          <p:panel>              <h:panelgrid columns="2">                  <p:selectonemenu                      id="someselect"                      value="#{testcontroller.countryname}"                      <f:selectitem itemlabel="select one" itemvalue="" />                      <f:selectitems value="#{addpatientprofilebb.patstatusselect}"                          itemlabel="#{testcontroller.countryname}"                          itemvalue="#{testcontroller.countrynameid}" />                      <p:ajax process="someselect" update="dialog" oncomplete="showdialog()"/>                  </p:selectonemenu>              </h:panelgrid>               <p:dialog id="dialog" header="login" widgetvar="dlg">                  <h:form>                      <h:panelgrid columns="2" cellpadding="5">                          <h:outputlabel for="username" value="username:" />                          <p:inputtext id="username" required="true" label="username" />                      </h:panelgrid>                  </h:form>              </p:dialog>          </p:panel>       </h:form>  </h:body> 

try changing

if($('#someselect').val() == 'india') {  

into

if($("select[name$='someselect_input'] option:selected").val() == 'india') {  

edit

you can improve selector changing

name$='someselect_input' 

into

name='yourformname\\:someselect_input' 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -