2

JSF code (dropdown menu populated with student names)

 <h:selectOneMenu  class="form-control" id="sels" onchange="getSelectedStud()">
       <f:selectItems value="#{user.allstuds}" var="user" itemValue="#{user.std_id}" itemLabel="#{user.name}" />
 </h:selectOneMenu >

JS code

 function getSelectedStud(){
             var sel_val = $("#sels :selected").val();
            $("#los").append("<option>"+ sel_val +"</option>");
        }

also tried this JS

function getSelectedStud(){
                 var sel_val = $("#sels").val();
                $("#los").append("<option>"+ sel_val +"</option>");
            }

can i get itemValue and itemLabel ?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

0

You don't need :selected, jQuery will give you the value currently selected.

function getSelectedStud(){
    var sel_val = $("#sels").val();
    $("#los").append("<option>"+ sel_val +"</option>");
}

But I'm not sure if itemValue will be translated as value, or is a custom attribute? If so, you would need .attr("itemValue");.

eisbehr
  • 12,243
  • 7
  • 38
  • 63