If you are unable to create a new account, please email support@bspsoftware.com

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

How to attach a custom onchange event to the check box group (8.3)

Started by eq85, 11 Jun 2009 06:22:17 PM

Previous topic - Next topic

eq85

Hello,

I am making some progress (since my previous post) and I think the problem now comes down to this:

I need just to assign a custom onchange event to the standard check box group, in order to prefrorm a programmatic "reprompt button click", so the connected (cascading) prompts are refreshed automatically according to the checked items.

I cannot figure out how to do this.

Here is the code:


function ReadCheckedItems () {
  var i, j, tmp, found;
  var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);

  tmp = "";
  found = false;

  // get the handle for the checkbox prompt - [div id="L1"] added around it
  var List1 = document.getElementById('L1');

// doesn't work! js error "Object expexted"
// tried to attach a function pressing the Reprompt button programmatically
  List1.onchange = AutoReprompt;

  for (i=0; i < List1.childNodes.length; i++) {
    var node_list = List1.getElementsByTagName('input');

    if (! found) {
      for (j = 0; j < node_list.length; j++) {
        var node = node_list[j];
     
        if (node.getAttribute('type') == 'checkbox') {
          found = true;
          if (node.checked) {
            if( tmp == "" ) {
              tmp = node.value;
            } else {
              tmp = tmp + "," + node.value;
            } //else
          } //if
        } //if
      } //for
    } //if ! found
  } //for
 
  //just to show that we've done all right
  alert (tmp);
}
 

function AutoReprompt () {
  SetPromptControl('reprompt');
}



The line "List1.onchange = AutoReprompt;" doesn't work!
I also tried the deprecated attachEvent function, but to no avail.

How to make it work?

I guess this is just a simple piece of knowledge I miss here.
Please help!



sandy_vitty

Hi eq

       Don't know if i am truly of any help but can u try this
       var List1 = document.formWarpRequest._oLstChoicesL1.checked.
       Let me know either way.

eq85

Thanks, this does work and makes the whole notation clearer (I mean, reference to the list as document.formWarpRequest._oLstChoicesL1).
I still don't know how to deal with checking/unchecking options for the check box group.

What I do now is trying to attach the following function to the appropriate object(s) onchange property(-ies):

function OptionCheckedModified () {
   SetPromptControl('reprompt');
}


This would reprompt the page with newly selected items, as I hope.

Here's what I found: this doesn't work if attached to the onchange events of List1 (check box group) or its options object (OptionList = List1.getElementsByTagName('input'))

It does work somehow if attached to every option individually:

for (var i=0; i < OptionList.length; i++) {
   OptionList [i].onchange = OptionCheckedModified;
};


Problems:
1. For some reason, this works only once after running the prompt page (after the first automatic reprompt it doesn't reprompt anymore by clicking the List1 options)
2. Even the first time, it works only when you check the option, then uncheck it, then click some other option - then it reprompts, seemingly properly.

Questions:
- Are there any other, more suitable on***** events to capture the checkbox checked state change? Some "oncheck" events maybe?
- What is the difference between the first load of the prompt page and the subsequent reloads due to remprompt? Why the behavior is different in these cases?

Thank you very much.

eq85

OK, narrowing down the problem...

The following code works fine upon the initial page load:

for (var i=0; i < OptionList.length; i++) {
   OptionList [i].onclick = OptionCheckedModified;
};


But it stops working after the reprompt (i.e. after the very first click on the check box group, selecting some checkbox, and correct reprompting the page).
How to make this work?

Thank you.