0

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??

5
  • 2
    Can you please post the VF page code? – Saroj Bera Nov 15 '16 at 9:03
  • I can't post the code because of CDP constraints – Debarun Sengupta Nov 15 '16 at 9:10
  • 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.. – Raul Nov 15 '16 at 9:13
  • Even with Jquery also it is coming as null.I used $("# surveypage:survey:j_id28:j_id29:answers2:0:mychkbx") – Debarun Sengupta Nov 15 '16 at 9:22
  • I dont think it is easy to guess what happens inside your code. Try to use developer tools of your browser to figure out what is working and what is not – kurunve Nov 15 '16 at 9:56
0

Although it would be helpful if you post the full VF page to build the $component.... expression if we use javascript,

solution using jQuery is straight forward:

$j= jQuery.noConflict(); $j(document).ready( function () { $j('id$="mychkbx"').value(); } );

Ps.. i am using handphone to type so syntax errors may be present

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.