0

I have these selectOneMenu component and now i want to get the selected value as parameter in a js method:

     <h:selectOneMenu id="onlyThis" value="#{bean.prio}"
        valueChangeListener="#{bean.prioChangeListener}" >
          <f:selectItems value="#{bean.prioSelectItems}" />
          <a4j:support event="onchange" ajaxSingle="true"                                           
               oncomplete="jsmethod(this.value).text;" /> 
     </h:selectOneMenu> 

With "this.value" i only get the key "1" as integer of the selectItems, but i want to get the values. Here is an example for a single SelectItem of "bean.prioSelectItems":

new SelectItem(1, "SomeText");

I want to get the value "SomeText".

How can put only this value as parameter in the js method "jsmethod"?

1
  • 2
    Looking through your questions, remind you must mark the answer which best fits your needs as the correct one. Click on the checkmark at the left of them, that way you'll reward the poster. Otherwise, considering you don't mark or even comment on them, people won't be interested on helping you... Commented Jan 28, 2014 at 8:09

1 Answer 1

1

For a dropdown

<select id="onlyThis">
    <option id="one" value="one">One</option>
</select>

the JavaScript will return

document.getElementById("one").value; //will return 'one'
document.getElementById("one").text; //will return 'One'

or you can access the selected option via the parent

document.getElementById("onlyThis").options[document.getElementById("onlyThis").selectedIndex];

If you've got the point the solution then will be:

oncomplete="jsmethod(this)"

with

function jsmethod(elem) {
    var selectedText = elem.options[elem.selectedIndex].text; //will equal to 'SomeText'
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.