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

Javascript to restrict values in textbox prompt

Started by sumit71277, 19 Mar 2012 09:44:37 AM

Previous topic - Next topic

sumit71277

Hello Experts,
I have two text box prompts on the prompt page. Product Code and Contract Year. User want to keyin the contract year on the report ( a single value). He also has another prompt called Product Code which is a multi input text box. I want to restrict the user to keyin a max. of 3 values for the Product Code text box prompt. The report should throw an error msg and restrict the user to only enter 3 values. Is there any javascript code that can achieve this?

CognosReports

Place this code anywhere on the form in an HTML Item:

STEP1
----------
<script language="javascript">
function CheckText()
{
var form = getFormWarpRequest();
var textBox = form._textEditBoxText1;
var parent=textBox.parentNode;
var select;
do {
parent= parent.parentNode;
var select= parent.getElementsByTagName("select");
} while(select.length ==0);
var opt = select[0].childNodes;
var length=opt.length
if (length >3) // User can select maximum of 3 values from prompt.
{
alert("You have selected " + length + " Values, Please select only 3 or less ");
}
else
{
promptButtonFinish();
}
}
</script>


PS: Text1 is the name of the textbox prompt.

STEP2
---------
Delete finish button and place an HTML item with following code:

<input type="BUTTON" class="clsPromptButton" onClick="CheckText()" value=" Finish ">


I hope this helps  :)

Thanks
Anshu