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

Clearing a Hidden Textbox via Javascript

Started by Dulanic, 01 Apr 2014 02:26:51 PM

Previous topic - Next topic

Dulanic

Hello,

I am attempting to clear all textboxes on my report when something specific happens. The problem I am running into is the javascript doesn't want to work if the textbox is hidden (box type = none). Part of my problem is cognos caches the textbox, so it still passes the value to a linked report even if the textbox is hidden. My idea to resolve this was to set all textboxes to '', but that isn't working as the javascript stops running as soon as it hits a hidden textbox. Any ideas on working around this?

I've even tried if ((var1.value!='')&& (var1.value!=null)) but as soon as it hits the line that references a non existent textbox it stops the script. The way I know this is happening is I put alert("test") as the last row and it shows the alert... but only if the textbox is shown.

navissar

When you set box type to none, the object doesn't render. No rendering means js won't be able to see it. Try wrapping your prompt with <div style="visibility :none"> and </div> tags. That'll hide it and still make it available for js.

Dulanic

Well, it's conditional. So what happens is based on another prompt, certain rows are shown and/or hidden based on another prompt. So my goal is to clear all of the textbox prompts that are showing and then reprompt the page. Is there a way to clear every visible textbox via js? That's what I was hoping this would do... I setup a if to clear each textbox, but it stops as soon as one isn't visible and doesn't continue to the remainder of them.

navissar

OK, now I think I got it.
Could you upload here either your script or, preferably, the XML of your report? It'll be easier to follow your precise scenario that way.

Dulanic

#4
Not sure if this helps a ton since I had to find/replace a lot of things but it shows the layout at least. The clear all selections button on the top left is kind of my testing link only. The javascript button to the right of the filters row is kind of where I want it to reset every showing textbox prior to the reprompt.

navissar

Right, I'll take a deeper look later on. In the meantime, here are some initial thoughts:
1. If you want to clear only the visible prompts, and you're on 10.2, why not use the promptAPI for this? I haven't seen it anywhere in the report. Try this sample:
http://pic.dhe.ibm.com/infocenter/cbi/v10r2m0/index.jsp?topic=%2Fcom.ibm.swg.ba.cognos.ug_cr_rptstd.10.2.0.doc%2Fc_prmpt_api_overview.html
You can add conditions to make sure you're only clearing textboxes...
2. If you wish to clear both visible and hidden text boxes, you'll need to change your conditional which sets boxtype none, because these aren't rendered. You can use the <div style="visibility:none"></div> method with a render variable on the HTML Item itself.

If this doesn't help I'll try to take a deeper dive .

Dulanic

Thanks! I got it to work with that API and a if checking the name was like the names i assigned the text boxes. Useful API, I am so used to cognos 8, I wasn't fully aware what it could do.

<script>
function clearAllValues() {
var oCR = cognos.Report.getReport("_THIS_");
var aControls = oCR.prompt.getControls();
for (var i = 0; i < aControls.length; i++) {
if (aControls[i].getName().match(/Text.*/)) {aControls[i].clearValues();}
}
}
</script>