COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: Grayson_Basil on 20 Jul 2016 02:18:04 PM

Title: Cognos 10 Radio Button Default Selection using JavaScript
Post by: Grayson_Basil on 20 Jul 2016 02:18:04 PM
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?
Title: Re: Cognos 10 Radio Button Default Selection using JavaScript
Post by: 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>
Title: Re: Cognos 10 Radio Button Default Selection using JavaScript
Post by: Grayson_Basil on 21 Jul 2016 10:47:37 AM
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>


Title: Re: Cognos 10 Radio Button Default Selection using JavaScript
Post by: dougp on 21 Jul 2016 11:28:44 AM
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.
Title: Re: Cognos 10 Radio Button Default Selection using JavaScript
Post by: Grayson_Basil on 22 Jul 2016 06:37:41 AM
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
Title: Re: Cognos 10 Radio Button Default Selection using JavaScript
Post by: dougp on 22 Jul 2016 12:37:25 PM
You're not being clear.  Is that what is currently happening or is that the desired effect?  How do you want it to behave?
Title: Re: Cognos 10 Radio Button Default Selection using JavaScript
Post by: Grayson_Basil on 25 Jul 2016 07:09:27 AM
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
Title: Re: Cognos 10 Radio Button Default Selection using JavaScript
Post by: dougp on 25 Jul 2016 11:42:58 AM
From the web application, pass the parameter in the URL.
Title: Re: Cognos 10 Radio Button Default Selection using JavaScript
Post by: Grayson_Basil on 25 Jul 2016 12:08:33 PM
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
Title: Re: Cognos 10 Radio Button Default Selection using JavaScript
Post by: Grayson_Basil on 11 Aug 2016 09:26:18 AM
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>