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

Cognos 10 Radio Button Default Selection using JavaScript

Started by Grayson_Basil, 20 Jul 2016 02:18:04 PM

Previous topic - Next topic

Grayson_Basil

I need the ability to use javascript to select the 1 static items in my radio button,

I cannot use the built in 'default selections' because there is another report function being used for this and my only solution is to use JS

I have this but this is not working..

<script language="javascript">
var form = getFormWarpRequest();
form._oLstChoicesopp.options[1].selected = true;

</script>

Any suggestions?

suri.cognos

just try with this it will work

<script language="javascript">

function EnableDefault(){
var form= getFormWarpRequest();
var list  = form._oLstChoicesox<PromptName>;

form._oLstChoices<PromptName>.options[1].selected = true;

}
</script>

Grayson_Basil

Quote from: suri.cognos on 21 Jul 2016 05:58:37 AM
just try with this it will work

<script language="javascript">

function EnableDefault(){
var form= getFormWarpRequest();
var list  = form._oLstChoicesox<PromptName>;

form._oLstChoices<PromptName>.options[1].selected = true;

}
</script>

I appreciate the answer, but this is not working


My valueprompt name is PromptName

this is my code

<script language="javascript">

function EnableDefault(){
var form= getFormWarpRequest();
var list  = form._oLstChoicesoxPromptName;

form._oLstChoicesPromptName.options[1].selected = true;

}
</script>



dougp

Since you are using Static Choices, Default Selections is the most suitable solution.  What is preventing you from doing that?

I'm sure you can do it with JavaScript, but it may not survive an upgrade.  You didn't say which version of Cognos you are using, but you'll probably want to try to use the Prompt API before using getFormWarpRequest.  Instructions are in the Report Studio help documentation.

Grayson_Basil

Cognos 10.2.1

We have this report embedded in an application.  When coming from the application, radio button 1 should be check, when running from Cognos Connection, radio button is not check

dougp

You're not being clear.  Is that what is currently happening or is that the desired effect?  How do you want it to behave?

Grayson_Basil

Desired Effect -

When Coming from embedded webpage - Date Radio Button should be LTF
When Coming from Cognos Connection - Date Radio Button should not have a default value.

So bottom line is I need to control the default value of a radio button with JS

dougp

From the web application, pass the parameter in the URL.

Grayson_Basil

Thanks for the suggestions

the LTD / YTD is not a parameter on the website app and I was told there will be too much effort to change the web app, so all work in on the Cognos Side.

Im not that good as JS and the new IBM API is terrible

Grayson_Basil

Well, finally got this working.. Again im sure there are better ways, but its working for me..
Working in Cognos 10.2.1

Radio Button is for year, 2014, 2015, 2016 are the values.




<script type="text/javascript">

var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);

var Basil = document.getElementsByTagName('input');
for (i = 0; i < Basil.length; i++) {
    if (Basil[i].type == 'radio' && Basil[i].value == '2014') {
        Basil[i].checked = true;
    }
}
</script>