Where could this JS be looping? Or...?

We shall ignore usability for the moment… I have a long list of checkboxes and labels, except the labels are not <label> elements, but it’s all one horrid, uber-nested table structure. When a user checks a checkbox, another table of associated values is inserted below the current table. I want to alert the user that he/she should review the new table and check the relevant checkboxes there. The first time a box is checked, all is well. Unchecking a box works fine. Checking subsequent boxes though, causes to alert to reappear in increments of 4 times! (That is, 1st box produces 1 alert; 2nd box produces 4 alerts, 3rd box produces 8 alerts, etc.) Here is the code:

function checkThese(ckbx) {
    "use strict";
    var txtAlert = 'Please scroll down and select all the applicable\ncritical details pertaining to:\n\n';
    var txtLabel = $(ckbx).closest('td').next('td').find('span').text();
    window.location.hash = '#B_SH_CRTTSK_TBL$scrolli$0';
    if ($(ckbx).prev('input').val() === 'A') {
        alert(txtAlert + txtLabel);
    }
}

TIA for any advice/suggestions!

A quick kludgy hack that doesn’t address the root of the problem?

function checkThese(ckbx) {
    "use strict";
    var alert_fired = false;
    var txtAlert = 'Please scroll down and select all the applicable\ncritical details pertaining to:\n\n';
    var txtLabel = $(ckbx).closest('td').next('td').find('span').text();
    window.location.hash = '#B_SH_CRTTSK_TBL$scrolli$0';
    if ($(ckbx).prev('input').val() === 'A' && alert_fired === false) {
        alert(txtAlert + txtLabel);
        alert_fired = true;
    }
}

Excellent, thanks! Still curious as to what is causing it to loop in multiples of four, though…

Can you please show us some of the HTML code that you are using. We can investigate and supply some answers once we see that.

I think so; this is actually a PeopleSoft application that’s been run through a tool that does most of the conversion to make the app responsive in design. Stand by…


I hope this screen capture is sufficient… Anyway, I had attached the listener function to all the checkboxes in this table. It works fine on the first box checked, and when you uncheck a box. When you check multiple boxes though, the JavaScript alert() appears 4 times for each box checked! <grr…>

OK, we’re getting there; now it increments the appearance of the alert() by only 2 for every box checked. :-\

Nope - I’m too lazy to type all of that in, and I’m likely to make tons of spelling mistakes that will not be representative of the problem you really are having.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.