Focal Point
Get WF Variable Value in Javascript Dynamically

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/8621019331

November 04, 2005, 02:07 PM
smiths
Get WF Variable Value in Javascript Dynamically
I am switching from cgi-bin to WFServlet, and a section of code that contains blocks of -HTMLFORM BEGIN and -HTMLFORM END intermingled with Dialogue Manager is now failing. So I want to convert the code to Javascript in one -HTMLFORM block. But I need to access the values of dynamically generated WebFocus variable names in Javascript, which I can't figure out how to do. A small sample of code illustrating what I am trying to accomplish is included below. Any help would be appreciated.

-SET &WFVARCNT = 2;
-SET &WFVAR1 = "X1";
-SET &WFVAR2 = "X2";

-HTMLFORM BEGIN

function test() {

WFVarValue = new Array();

// dynamically build WF variable name, then
// store value of variable
for (idx=1; idx<=!IBI.AMP.WFVARCNT;; idx++) {
WFVarName = '!IBI.AMP.WFVAR' + idx + ';';
// -> need WFVarValue[idx] = value of WFVarName
}
}

-HTMLFORM END
November 04, 2005, 03:57 PM
Francis Mariani
Sean, welcome to FocalPoint.


What you want to do is not pretty! Here is a solution.

-SET &ECHO=ALL;

-SET &WFVARCNT = 2;
-SET &WFVAR1 = 'X1';
-SET &WFVAR2 = 'X2';

-HTMLFORM BEGIN


<script type="text/javascript">

// Declare Array
WFVarValue = new Array();
/*
-HTMLFORM END

-REPEAT REP_END1 FOR &COUNTER FROM 1 TO &WFVARCNT

-SET &VAR = &WFVAR.&COUNTER;

-HTMLFORM BEGIN
*/
WFVarValue[!IBI.AMP.COUNTER;] = '!IBI.AMP.VAR;';
/*
-HTMLFORM END

-REP_END1

-HTMLFORM BEGIN
*/
function test() {

for (idx=1; idx<=!IBI.AMP.WFVARCNT;; idx++)
{
alert(WFVarValue[idx]);
}
}





-HTMLFORM END
The Javascript comment tags (/* */) are there to disable the HTML comments that WebFOCUS puts in at every HTMLFORM BEGIN and END. To see what I mean, view source after running this fex.

Francis.

This message has been edited. Last edited by: <Maryellen>,


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
November 04, 2005, 04:57 PM
smiths
Francis,

Thanks for the welcome, and even more thanks for this solution! You are awesome!! Adding the /* and */ worked like a charm!! We're going to have to get you bumped up to 5 stars!

Thanks again,
Sean
November 04, 2005, 06:17 PM
Francis Mariani
Nice to see a happy customer!