0

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.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
ANIS BOULILA
  • 71
  • 2
  • 10
  • possible duplicate of [How to refer to a JSF component Id in jquery?](http://stackoverflow.com/questions/7132061/how-to-refer-to-a-jsf-component-id-in-jquery) and [Javascript fails to access a JSF component by calling through its id](http://stackoverflow.com/questions/6576258/javascript-fails-to-access-a-jsf-component-by-calling-through-its-id) – BalusC Nov 17 '11 at 13:04

1 Answers1

1

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.

Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118