I need to get the value of below control using javascript.I am getting null every time I am using the below javascript code
<apex:inputCheckbox value="{!selectedVal2}" id="mychkbx" onchange="is_checked();" />
Javascript code used
document.getElementById("{!$Component.surveypage.survey.answers2.mychkbx}")
Where, surveypage=id of the page survey=id of the form answers2=page block table id mychkbx=id of the input field.
Even when i am directly referencing the id of the field generated then also it is coming as null
Id generated
document.getElementById("surveypage:survey:j_id28:j_id29:answers2:0:mychkbx")
Please let me know what needs to be done in this case or where I am doing wrong??
apex:pageBlockTable
adds a number for Id of each element in a row, for Visualforce components. (As you can see here - surveypage:survey:j_id28:j_id29:answers2:0:mychkbx). Accessing elements with jQuery is easier..