ANIS BOULILA
ANIS BOULILA

Reputation: 69

How to access the JSF's SelectItem from jQuery or JavaScript

Is there a way to access to an id of selectItem JSF from JavaScript or jQuery?

<a:commandButton id="ajaxButton" value="change" onclick="selectCheck()">
</a:commandButton>

<h:selectManyCheckbox id="check" >
    <f:selectItem id="myCheckbox" itemLabel="India" itemValue="India"  />
    <f:selectItem itemLabel="China" itemValue="China" />
    <f:selectItem itemLabel="Germany" itemValue="Germany" />
    <f:selectItem itemLabel="USA" itemValue="USA" />
</h:selectManyCheckbox>

I try to access the id of the component but it returns null:

function selectCheck() {
    var obj = document.getElementById("myCheckbox");
    alert(obj);
    obj.checked=true;
}

I want to check any of theses checkboxes dynamically by JavaScript or jQuery.

Upvotes: 0

Views: 2195

Answers (1)

J&#246;rn Horstmann
J&#246;rn Horstmann

Reputation: 34014

Have you looked at the generated html to see if thats really the id of the element? JSF usually prepends the id of the form and some other container elements. The real id might be something like myForm:myCheckbox.

Upvotes: 1

Related Questions