Google Search

Monday, March 9, 2009

Script For Limiting the Multi-Select Prompt

This script is used to limit the selection in the multiselect prompt.Just place the code in html item

< script>

function CheckNum() {

// initialize the counter
var Counter = 0;
var i;

// get the handle for the 1st checkbox prompt - add div around them to distinguish
var prompt1 = document.getElementById('PayerSelect');

// find all the children of the div of type checkboxes.
for (i=0; i < prompt1.childNodes.length; i++)
{

var node_list = prompt1.getElementsByTagName('select');
for (var i = 0; i < node_list[0].length; i++)
{
var node = node_list[0];
if (node.options(i).selected == true)
{
Counter++;
}
}
}

// If the counter is greater than 15, display an alert message.
if (Counter > 15){
alert("Please select less than 15 Payers.");
return false;
} else {
// Just display a message, we don't really want the form to submit
// for testing. In the case of production, the alert condition
// would be removed and the promptButtonFinish() call uncommented.
//alert("Form passed validation!");
promptButtonFinish();
}
}
< /script>
< b>
< input type="button" style="width:65px;height=25px;border:1px solid black;font-size=9pt; font-family:ARIAL;font-weight:bold; background-color=#3399CC" name="Finish" value="RUN" class="Prompt Button" onClick="CheckNum();">
< /b>


------------------------------------
< div id="PayerSelect">

-----------------------------------------
< /div>

2 comments:

  1. HI Uday,
    I am using Cognos 8.4 version and I am trying to use your code for a checkbox prompt and I get an error that the code is invalid. I dont know any javascripting. Please help!

    ReplyDelete
  2. Hi Uday,
    Now I got the code working but it does not give the expected results. What am I doing wrong?

    ReplyDelete