Parag A
Parag A

Reputation: 453

how to get selected index for h:selectOneMenu

I want to get the selected index for my h:selectOneMenu field.

I can either use javascript or jquery

please help

<h:selectOneMenu id="myId" value="#{AddScriptBean.scriptEngine}"  >
        <f:selectItems value="#{AddScriptBean.scriptEngines}"/>
</h:selectOneMenu>

Upvotes: 2

Views: 2180

Answers (1)

PSL
PSL

Reputation: 123739

Assuming your selectOneMenu is rendered as select.

With jquery you can use this to get the selected index.

 $(function(){
        $('#myId').prop('selectedIndex')
    });

With javascript it would be

document.getElementById('myId').selectedIndex

Upvotes: 1

Related Questions