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, 2016 at 9:03
  • I can't post the code because of CDP constraints Nov 15, 2016 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, 2016 at 9:13
  • Even with Jquery also it is coming as null.I used $("# surveypage:survey:j_id28:j_id29:answers2:0:mychkbx") Nov 15, 2016 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, 2016 at 9:56

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .