0

I am trying to save the value of selected item from p:selectOneListbox on a button click using jquery.

Tried to replicate but it didn't work for me : How to get the value of <p:selectOneMenu> in jquery?

<p:selectManyMenu id="advanced1" widgetVar='commmentWidget'
                        value="#{decisionTreeBean.option1}"  showCheckbox="true" styleClass="XXXX">
                        <f:selectItems value="#{decisionTreeBean.XXXX}" var="X"
                            itemLabel="#{X}" itemValue="#{X}" />
                    </p:selectManyMenu>

Below jquery didn't work (name attribute is the name from the generated HTML)

jQuery(".generateBtn").on("click",function(event){
                     var $element = jQuery("select[name='A3128:searchForm:basic1_input']option:selected").val();
                    alert($element);

                });

Generated HTML:

How do I store the text value of the item selected from selectOneListbox into a variable.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Naxi
  • 1,504
  • 5
  • 33
  • 72
  • Please refrain from adding tags in the title. They are sort of automatically added by stackoverflow. And effectively this is not PrimeFaces related but a pure html/javascript/jquery question. And why are you trying to do all this pure client-side? – Kukeltje Sep 24 '18 at 15:50
  • Maybe a blank is missing in front of `option:selected` – Holger Sep 25 '18 at 07:25

0 Answers0