ODBiC Discussion Board


RE: set variable to string containing variables to be evaluated later, tom, 07-19-2005

You may be over-complicating it ;-)

by Roger Harris, July 19, 2005 16:32

When you set a variable to a quoted character string, any embedded variable references are NOT evaluated at that point. When you USE that variable anywhere in the script, however, embedded variables will be evaluated at that point, UNLESS you use the $varstr( ) function (but I don't think that's what you need to do in this case).

Consider these statements:

<!--SET x="Value of x"-->
<!--SET y1="The value of x is $x$"-->
<!--SET y2="The value of x is" $x$-->
At this point, variable y1 will still be "The value of x is $x$" because the $x$ was inside the quotes; but y2 will be "The value of x is Value of x" because $x$ was evaluated during the SET statement.

Ordinarily, it may not make a difference if a variable reference inside another variable is evaluated when that variable is set or if it's evaluated when that variable is used somewhere in the script. For example, after the statements above, if you then use $y1$ or $y2$ anywhere in the script, the output will be identical, "The value of x is Value of x", because the value of $x$ hasn't changed. But any time that the value of an embedded variable changes between those two events, then it does matter. In your case, it does matter, because the embedded variables will change with each iteration through the EACHROW loop, and you want the current values in each row read from the database to be in the output line for that row.

I'm not sure what your javascript function is doing, but remember that it will be evaluated by the browser after it receives the output. So I don't think that's a consideration here EXCEPT that you need to be careful about quotes that ODBscript will interpret and quotes that the javascript will need and expect when the page is sent to the browser. (ODBscript and javascript will both allow you to use either single-quotes or double-quotes around a text string, and whichever you use, the other type of quote will be treated as an ordinary character inside the quoted string.)

So, assuming that you do need the javascript function in the page that's sent to the browser, I think your two SET statement should be:

...
<!--SET urlString="javascript:removeProc('$title$', $id$)"-->
...
<!--SET urlString="/cgi-bin/odbic/odbic.exe/MainFrame/library/Document Library/procedures/admin/modify.htm?modid=$id$"-->
...
Since both of these SET strings are fully inside double-quotes, the variable references will NOT be evaluated at that point, and urlString will contain exactly what's inside those quotes (i.e., everything except the outside double-quotes, and the variable references will still be variable references). The single-quotes around the '$title$' reference will still be there, so they will passed through to the output page, and the javascript function argument will be a properly quoted character string.

So, now when you go into your EACHROW loop and you use the <a href="$urlString$"> reference, the embedded variables will be evaluated using the current values at that point, i.e. the values from the current database row. And, I think that's all you need to do. (Note that I put "$urlString$" in quotes, but that's because you really should do that for proper HTML. Also note that I used double-quotes instead of single-quotes for that because one of your javascript arguments already has single-quotes around it, so you don't want to confuse the browser. Since this is not an ODBscript SET statement -- it's just ordinary output -- ODBscript will leave those double-quotes in the output HTML.)

(Hmmm... I guess it IS kinda complicated, but you just need to carefully observe the rules about embedded variables ;-)


Replies:


Post Your Reply:

Name   
E-mail  optional
Topic  
Message:

HTTP Link: 
Link text: 


Copyright 1997-2003, Roger Harris. All rights reserved.