Reputation: 43
I am creating a dynamic form which hides/unhides fields based on selection of radio buttons. I was using normal javascript function as given below which is working fine in my portal environment(the ids are the JSF ids which i get by viewing source).
function printHiddenValue(){
alert("hello");
alert(document.getElementById('A1938:j_idt4:create-ticket:hiddenId').value);
if(document.getElementById('A1938:j_idt4:create-ticket:j_idt19:0').checked){
alert("incident sellected")
} else
{
alert("change sellected")
}
}
but fails when i deploy the war in different environment as differnrt ids are generated by the portal environment.
Upvotes: 0
Views: 597
Reputation: 14277
You should not rely on dynamic ids, not just A1938
part of id but also j_idt4
may change if you change structure of your page for example. You should assign id to component j_idt4
, and for first part you can use EL #{facesContext.externalContext.response.namespace}
to get namespace of your portlet:
document.getElementById('#{facesContext.externalContext.response.namespace}:j_idt4:create-ticket:hiddenId')
Upvotes: 1