Reputation:
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"?
Upvotes: 0
Views: 593
Reputation: 11742
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'
}
Upvotes: 1