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
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.
Also, you have no need to check if your checkbox are checked becouse those are already onclick functions.
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 theclick
event in a situation like this — theinput
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 befalse
.