0

i need to acess componets dynamic id in javascript also i tried many ways on the internet but seems not working..

i tried this way..

<ice:selectBooleanCheckbox id="chkk" binding="#{input1}" onchange="test(this)"/>

so that you can just print its client ID elsewhere in the view by UIComponent#getClientId().

test(){
var input1 = document.getElementById('#{input1.clientId}');

alert(input1);

}

Here i am getting input1 values as null..

and i am not doing anychnges in java side plz suggest me where i am mistaken...

Thanks for help in advance.

vinod
  • 1,178
  • 4
  • 16
  • 42

1 Answers1

0

You define id for your form, then you define id for your checkbox as you have already done ("chkk") and you can access your element as follows:

document.getElementById('myFormId:chkk')
Oskars Pakers
  • 699
  • 3
  • 11
  • thanks for the reply @oskars but this is not the way to access dynamic id.. it will become static – vinod May 12 '14 at 12:42
  • Indeed. Why have you defined id of an element then? Anyway, have you tried this: http://stackoverflow.com/questions/6045307/how-can-i-know-the-id-of-a-jsf-component-so-i-can-use-in-javascript – Oskars Pakers May 12 '14 at 12:51
  • yes i tried this link.. i am working on dynamic tabs so its generating new id's when the new tab gets open and i can not assign static id for component because of duplicate id issue.. – vinod May 12 '14 at 13:11
  • have you tried accessing the element like this: test(element){ element.value} ? – Oskars Pakers May 12 '14 at 13:31
  • yes i tried and it is giving me the value as well too and some part of my code is also working... but i need to access id of components – vinod May 12 '14 at 14:12