This discussion is archived
6 Replies Latest reply: Jan 16, 2013 8:11 AM by KeithMalay RSS

Checkbox Onclick action

TAC Newbie
Currently Being Moderated
Hi all,

I am working in apex 4.2.1.

I'm having an odd problem with a checkbox on a tabular form. I created the checkbox by setting hte display as to "Simple Checkbox". The value of the underlying column sets to "Y" wehn checked and "N" when unchecked. This is what I want. The next thing I was trying to accomplish is to call a javascript function when the checkbox is clicked. So I put onclick="calculateTotal(this);" in the element attributes field. The code that it is calling is listed below. When I run the app and check the box I can seee I am entering the calculateTotal function. Each of the alert functions is displaying what I would expect until I get to alerts 'IAH5' and 'IAH6'. For each of those I get an "undefined" in the alert.

So to see if this had soemthing to do with the checkbox and added an onchange="calculateTotal(this);" to another field in my tabular form and ran it. This time I did not click on the checkbox but went into the field that I put the onchange on. When I changed this field and navigated away from it the function worked as I would expect. It displayed the appropriate values for each of the alerts and updated the fields on the screen as designed.

Does anyone have any suggestions as to what might be wrong?

Any help would be appreciated.


<script type="text/javascript">
function calculateTotal(pThis)
var vRow ='_')+1);
var vPerformedOn = $v('P19_PERFORMED_ON');
alert('IAH3 performed on '+vPerformedOn);
var vPerformedMileage = $v('P19_PERFORMED_MILEAGE');
alert('IAH4 performed mileage '+vPerformedMileage);
html_GetElement('f08_'+vRow).value = vPerformedOn;
alert('IAH5 '+html_GetElement('f08_'+vRow).value);
html_GetElement('f10_'+vRow).value = parseInt(vPerformedMileage,10);
alert('IAH6 '+html_GetElement('f10_'+vRow).value);
  • 1. Re: Checkbox Onclick action
    KeithMalay Explorer
    Currently Being Moderated

    Can you post an example of your problem on

    If so, update this thread with a link to your application and I'll take a look.

    Keith Malay
  • 2. Re: Checkbox Onclick action
    Tom Petrus Expert
    Currently Being Moderated
    Checkboxes generate differing HTML from the usual text field (ie your description field, on which you put the onchange handler).
    Checkbox HTML consists of HTML for the checkbox and a hidden item.
    <input type="checkbox" onclick="if (this.checked) {apex.jQuery('#f08_0002').val('');} else {apex.jQuery('#f08_0002').val('');}" id="f08_0002_01" value="" name="f08_NOSUBMIT" autocomplete="off">
    <input id="f08_0002" type="hidden" value="" name="f08" autocomplete="off">
    So when you add an onclick on the checkbox and retrieve the ID, obviously the ID will be off.
    Results in
    You can use
    "f08_0002_01".substr("f08_0002_01".indexOf('_')+1, 4)
    Edited by: Tom on Jan 16, 2013 3:28 PM: forum noms
  • 3. Re: Checkbox Onclick action
    TAC Newbie
    Currently Being Moderated

    Workspace - tconte
    userid guest
    pw tcdemo
    app= fleet

    go to the equipment tab choose the __SH__ link on the first row. enter a value in the performed mileage item. go to the first row in the tabular form and click done. it will walk you through the alert messages and you can see the undefineds for IAH5 and IAH6. Nothing happens to the row.

    Now if you go back and put something in the description field and leave the field it will fire the same code and IAH5 and IAH6 have the correct values and update the screen.

    Let me know if you have any questions.


  • 4. Re: Checkbox Onclick action
    KeithMalay Explorer
    Currently Being Moderated

    I made a small change on your instance. Can you login and retest?

    Keith Malay
  • 5. Re: Checkbox Onclick action
    TAC Newbie
    Currently Being Moderated

    It works the way I intended. In looking at the change you made I see you added a length to the substr so that it ignores the trailing "_##". Now it makes sense as to what was happening. It just couldn't find an item name F08_0001_01 or F10_0001_01. Putting in the length of 4 caused it to just pull back the "0001" portion. i.e. the row_number.

    Now to add in the next few pieces!

    Thank you very much.

  • 6. Re: Checkbox Onclick action
    KeithMalay Explorer
    Currently Being Moderated
    After I logged in and made the change, I came back to update the thread and saw that the other Tom :) had suggested the same fix.

    Glad it worked for you.

    Keith Malay


  • Correct Answers - 10 points
  • Helpful Answers - 5 points