Setting the Value of a Text Box Prompt with Javascript in Cognos 8.4
Posted by Darren Nelson on Thu, Oct 15, 2009
Hello again,
I've been working through a specific issue where I wanted to dynamically set the value of a Cognos 8.4 Text Box Prompt with Javascript. I immediately went to my previous blog posting to copy and paste the code! Unfortunately, this only got me half way.
Since the Cognos prompts aren't simply HTML form elements, it did not suffice to try searchPrompts("Address").value="HELLO!!!". What I REALLY needed to do was simulate the user typing the desired text. So, after spending some time trying to understand what is going on in the background, I'm pleased to announce that with just a few lines of Javascript, I can easily set the value!
<SCRIPT> function setTextBoxPromptValue(promptName, promptValue) { var SpotOnTargetControl = G_PM_THIS_.getControlByName(promptName); var SpotOnPCType=SpotOnTargetControl._type_; if(SpotOnPCType == "cognos.Prompt.Control.Text") { SpotOnTargetControl.bParse(promptValue,""); SpotOnTargetControl.setCurrentValue(); SpotOnTargetControl.checkData(); } } </SCRIPT> <A onclick='setTextBoxPromptValue("Address","520 Bronson Ave.")' href="#">Set Value for Address</A><BR>