skip to Main Content

In a Cognos report i have 2 checkbox prompts named :

  • ChoicesIndicator1_VALUE
  • ChoicesIndicator1_VALUE_b1

When the first one is clicked / unchecked, the second one has to also be unchecked.

I can’t do this with Cognos so i’m using javascript.

The idea is as follows :

<script>   

var form = getFormWarpRequest();
var myList  = form._oLstChoicesIndicator1_VALUE 
var myListb1  = form._oLstChoicesIndicator1_VALUE_b1 

myList.onclick = function() {myFunction()};

function myFunction()
{
          if(myList.checked == true)
          {   
             myList.checked = false;  
          }
}

</script>    

The if is working but not the "myList.checked = false"; (an alert("hello"); is working).
So i guess there’s something wrong.
Note : i’d rather use the prompt name if possible. If the prompt ID is needed, can it be attached to the prompt with JS code ?

Anybody knows how to correct this?

2

Answers


  1. I think the problem is that when you are checking that checkbox, you are at the same time unchecking it. I modified that a bit. Now it should work.

    var form = getFormWarpRequest();
    var myList  = form._oLstChoicesIndicator1_VALUE;
    var myListb1  = form._oLstChoicesIndicator1_VALUE_b1;
    
    myList.onclick = function() {myListOnclick()};
    myListb1.onclick = function() {myListb1Onclick()};
    
    function myListOnclick() { 
      myListb1.checked = false;
    }
    
    function myListb1Onclick() {
      myList.checked = false;  
    }

    Also, you have no need to check if your checkbox are checked becouse those are already onclick functions.

    Login or Signup to reply.
  2. You are saying "When the first one is clicked / unchecked, the second one has to also be unchecked." So, here is an event listener for the input event (don’t use the click event in a situation like this — the input event will happen when a value of an input has changed). If the value changes (there is input) on the _oLstChoicesIndicator1_VALUE input, the checked value of _oLstChoicesIndicator1_VALUE_b1 will be false.

    //var form = getFormWarpRequest();
    var form = document.forms.form01;
    
    form.addEventListener('input', e => {
      if (e.target.name == '_oLstChoicesIndicator1_VALUE') {
        e.target.form._oLstChoicesIndicator1_VALUE_b1.checked = false;
      }
    });
    <form name="form01">
      <label>No. 1: <input type="checkbox" name="_oLstChoicesIndicator1_VALUE"></label>
      <label>No. 2: <input type="checkbox" name="_oLstChoicesIndicator1_VALUE_b1"></label>
    </form>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search