在primefaces中使用javascript从selectOnemenu获取选定的值,然后打开一个对话框 [英] get selected value from selectOnemenu using javascript in primefaces and open a dialog box

查看:103
本文介绍了在primefaces中使用javascript从selectOnemenu获取选定的值,然后打开一个对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用JavaScript/jQuery获取PrimeFaces <p:selectOneMenu>的选定值?

How can we get the selected value of PrimeFaces <p:selectOneMenu> using JavaScript/jQuery?

我正在尝试以这种方式获取它,但是如果有条件,它就不会进入内部,这意味着该元素的ID不正确.

I am trying to get it this way, but it does not go inside if condition, which means that the ID of the element is 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>

推荐答案

尝试更改

if($('#someSelect').val() == 'India') { 

进入

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

编辑

您可以通过更改

name$='someSelect_input'

进入

name='yourFormName\\:someSelect_input'

这篇关于在primefaces中使用javascript从selectOnemenu获取选定的值,然后打开一个对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆