Hi,
I'm trying to write some JS to trigger an event (function) each time a one of the 3-values in a checkbox prompt is being changed - Checked or Un-checked
My JS code is :
<script>
pPT_Box=document.formWarpRequest._oLstChoices_procedure;
pPT_Box[0].onclick=setFinishButton(0);
pPT_Box[1].onclick=setFinishButton(1);
pPT_Box[2].onclick=setFinishButton(2);
function setFinishButton(i) {
alert (i);
}
</script>
But something is not right, beacuse I'm getting JS error immediately when running the report, without making any selection.
Webpage error details
Message: Not implemented
Line: 456 (pPT_Box[0].onclick=setFinishButton(0);)
Char: 1
Code: 0
URI: http://172.16.5.144:8081/cgi-bin/cognos.cgi
Report spec is attached for refference.
Try pPT_Box=document.formWarpRequest._oLstChoices_procedure.options;
OR pPT_Box.options[0].onclick
I really need to get over there one day and do a presentation on the new Prompt API.
Quote from: PaulM on 12 Aug 2013 12:30:40 PM
Try pPT_Box=document.formWarpRequest._oLstChoices_procedure.options;
OR pPT_Box.options[0].onclick
I really need to get over there one day and do a presentation on the new Prompt API.
Yes you do!
Hi Paul,
I tried your 2 solutions, but i'm getting the following error
Message: Unable to get value of the property '0': object is null or undefined
Line: 142 ( pPT_Box.options[0].onclick=setFinishButton(1); )
And yes, I think you should come here, and give your presentation :)
Hi Or,
Try the following:
<script language="javascript">
var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
if ( !fW || fW == undefined)
{ fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );}
/*
* Function: addEvent
* Author: Dan Fruendel
* Attachs an event or adds an event listener depending on the browser.
*/
var
addEvent = function(element, event, func)
{
if(element.addEventListener)
{
addEvent = function(element, event, func)
{
element.addEventListener(event, func, false);
return true;
};
}
else if(element.attachEvent)
{
addEvent = function(element, event, func)
{
return element.attachEvent("on" + event, func);
};
}
else
{
addEvent = function(element, event, func)
{
var oldEventHandler = element['on' + event];
element['on' + event] = function()
{
//using .apply to pass on anything this function gets.
if(typeof(oldEventHandler) === "function")
{
oldEventHandler.apply(element, arguments);
}
func.apply(element, arguments);
}
return true;
};
}
return addEvent(element, event, func);
}
var getSource = function() {
var targ;
if (!e) var e = window.event;
if(!e) return false;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
return targ;
}
var getMethods = function(myObject) { var funcs=[]; for(var name in myObject) { funcs.push(name) } return funcs.join(', '); }
var test=function() {document.getElementById('yo').innerHTML = getSource().value}
var cb = fW._oLstChoices_test;
for(var i=0;i<cb.length;i++){
addEvent(cb[i],'click',test);
}
</script>
<div id="yo"></div>
Looks like I was wrong, you don't need to use options.
I'm using addEvent as I don't want to override any native Cognos functionality. There's an easier and better way of doign it using the Prompt API in 10.2, but the client I'm at now is still in the stone age and only has 10.1.1 so I can't easily test it.
You can also get away with addEvent(cbi[0],'click',function() {alert(1)});
Hi,
I have tried to use the last solution you gave, but it didn't work. However, I stumble upon the following IBM page -
http://www-01.ibm.com/support/docview.wss?uid=swg21393335 (http://www-01.ibm.com/support/docview.wss?uid=swg21393335)
Which included the following example (alertOnClickRadio.txt) with a bit more complicated Javascript, but it is working :
<script>
function testFunc()
{
// alert("in testFunc ");
SetPromptControl('reprompt');
return;
}
function alertOnclick(valuePromptName)
{
var prompt1 = document.getElementById('radioBox1');
var node_list = prompt1.getElementsByTagName('DIV');
var el;
for (var i = 0; i < node_list.length; i++)
{
var node = node_list[i];
if (node.getAttribute('className') == 'clsPromptComponent' || node.className == 'clsPromptComponent')
{
el = node;
break;
}
}
if (el != null)
{
el.onclick=function(){testFunc();};
}
else
{
alert("Unable to select a node");
}
}
alertOnclick('valPrompt1');
</script>