Skip to main content
November 22, 2009
Question

Evaluating a dynamic variable

  • November 22, 2009
  • 1 reply
  • 378 views

Hi I'm trying to write a little function to create, populate and select defaults for list type drop down menus, what I have works, but there is a small problem.

The select control name is passed as an argument to the function:

        <li>
                <label for="type">Type</label>
                <select name="type" id="type" />
                    <cfscript>selectOptions('type','VehicleTypes','type','id');</cfscript>
                </select>
            </li>

When the function gets a hold of it it needs to be eveluated, I'm using 'evaluate()' - but I understand that there are problems with evaluate.
Is there another method to do this?  [i.e. address the value of a dynamic variable] See below.

    <cffunction name="selectOptions" access="public" output="yes" returntype="string">
               
        /*------ unrelated code removed -----*/
   
        <cfscript>

                           
            for (i = 1;i lte showoptions.recordcount;i++){
                vlu = showoptions[value];
                txt = showoptions[column];
                if(evaluate(formvar) is vlu){sel = 'selected="selected"';}else{sel=formvar&' '&vlu;}
                options = options&'<option value="'&vlu&'" '&sel&' >'&txt&'</value>';
            }
            writeoutput(options);
        </cfscript>

    </cffunction>

-thanks

-sean

This topic has been closed for replies.

1 reply

Inspiring
November 22, 2009

The main problem with evaluate is that it's slow.  Array notation is faster.  The syntax is:

Structure["constant part" & variable part]

The structure could be form, url, arguments, or a structure you created yourself.

November 23, 2009

Been down that road, thought I had at any rate.  I was trying to evaluate 'arguments.formvar' or arguments[formvar] .... when in fact I needed to evaluate a form variable. - duhh!

sometime you just need a nudge in the right direction.. thanks.