Skip to main content
Participant
July 18, 2008
Question

Dynamically disable cfinput

  • July 18, 2008
  • 2 replies
  • 1507 views
I want to disable a radio button based on a variable isUserCreditApproved. The attached code is what i came up with however CF chokes with

Invalid CFML construct found on line 9 at column 84.
ColdFusion was looking at the following text:

#

The CFML compiler was processing:

* A cfinput tag beginning on line 9, column 33.


The error occurred in D:\path\to\file\testcredit.cfm: line 9

7 : <tr><td>
8 : <cfform name="myform" method="post">
9 : <label><cfinput type="radio" name="paytype" value="billme" #IIF(not isUserCreditApproved, DE('disabled="disabled"'), DE(''))#>Bill Me</label><br>
10 : </cfform>
11 : </td></tr>

How can I get the functionality that i want? Or, Is what i'm trying even possible?
    This topic has been closed for replies.

    2 replies

    Inspiring
    July 19, 2008
    One cannot build CFML source code at runtime and expect it to execute.
    CFML is just source code: the CF engine compiles it when it's first called,
    and thereafter executes the resultant byte code. So any code one wants to
    execute needs to already be present at compile time.

    If you're using CF8 you can pass an attribute collection to a <cfinput>
    tag, into which you can optionally insert a DISABLED key according to your
    IF logic.

    On previous versions, have the IF logic around the <cfinput> tag,
    duplicated it for each of the IF/ELSE blocks with or without the DISABLED
    attribute as dictated by your requirement.

    --
    Adam
    jeremyisAuthor
    Participant
    July 21, 2008
    Yeah that's what i kinda figure the problem was. So I see two solutions

    1 ) Use regular input form fields and use that same logic as in my first post to dynamically include the disabled attribute.

    2) Use an cfif to include the appropriate cfinput field one with the disabled attribute and one without.

    As for best practices, I'm guessing the #2 is the preferred method especially for readable code. Is that right?
    Inspiring
    July 18, 2008
    I suggest being more methodical. Do your if/else logic first and set a variable to either disabled='disabled' or an empty string. Then output that variable in your cfinput tag.

    Or you might just be missing a cfoutput tag.