Professional Web Applications Themes

Using IIf() with IsDefined() - Macromedia ColdFusion

What have I missed about IIf()? Consider this example form input: <input type='text' name='foo' id='foo' value='#IIf(isDefined('form.foo'),form.foo,query.f oo)#' /> I do this because I use the same form and code block for doing insert and updates. Also, if the submitted form does not pass validation, I want to let the user keep any good information they've entered, hence the check for the existing of the value in the form scope. But what I keep getting is an error saying 'foo is not defined in form'. What's up?...

  1. #1

    Default Using IIf() with IsDefined()

    What have I missed about IIf()? Consider this example form input: <input
    type='text' name='foo' id='foo'
    value='#IIf(isDefined('form.foo'),form.foo,query.f oo)#' /> I do this because I
    use the same form and code block for doing insert and updates. Also, if the
    submitted form does not pass validation, I want to let the user keep any good
    information they've entered, hence the check for the existing of the value in
    the form scope. But what I keep getting is an error saying 'foo is not defined
    in form'. What's up?

    mate of the state Guest

  2. #2

    Default Re: Using IIf() with IsDefined()

    Why don't you use CFIF / CFELSE?
    paross1 Guest

  3. #3

    Default Re: Using IIf() with IsDefined()

    Well, clearly that is the option I am left with. But this is less code, and
    therefore a better option. I have never gotten a clear picture of how to use
    IIf(), so I am thinking I'm missing something here.

    mate of the state Guest

  4. #4

    Default Re: Using IIf() with IsDefined()

    You might want to read up on the usage of IIF....

    [url]http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/funct117.htm#wp1105815[/url]

    The IIf function is a shortcut for the following construct:

    <cfif condition>
    <cfset result = Evaluate(string_expression1)>
    <cfelse>
    <cfset result = Evaluate(string_expression2)>
    </cfif>

    The expressions string_expression1 and string_expression2 must be string
    expressions, so that they are not evaluated immediately as the parameters of
    IIf. For example:

    IIf(y is 0, DE("Error"), x/y)

    If y = 0, this generates an error, because the third expression is the value
    of x/0 (invalid expression).

    ColdFusion evaluates string_expression1 and string_expression2. To return the
    string itself, use the DE function.

    Phil


    paross1 Guest

  5. #5

    Default Re: Using IIf() with IsDefined()

    Okay, I sort of was clear on that... but then why do I still get an error with this syntax:

    #IIf(IsDefined('form.foo'),DE(form.foo),DE(query.f oo))#

    Quotes around DE arguments?
    mate of the state Guest

  6. #6

    Default Re: Using IIf() with IsDefined()

    No, as suspected, that returns that string, instead of the value for that variable.
    mate of the state Guest

  7. #7

    Default Re: Using IIf() with IsDefined()

    According to your link, paross1, it appears I need to incorporate Evaluate() with DE() in that instance. Thanks!
    mate of the state Guest

Similar Threads

  1. Isdefined() not working in MX6
    By s6868 in forum Coldfusion - Getting Started
    Replies: 3
    Last Post: September 7th, 08:57 PM
  2. IsDefined In Coldfusion
    By wilsite in forum Coldfusion - Getting Started
    Replies: 4
    Last Post: July 1st, 05:15 AM
  3. Problem with IsDefined()
    By Fizzled in forum Macromedia ColdFusion
    Replies: 2
    Last Post: April 28th, 04:00 PM
  4. isDefined sketchiness
    By sofanova in forum Macromedia ColdFusion
    Replies: 4
    Last Post: March 10th, 09:27 PM
  5. <cflock> with isdefined...help.
    By Supra LTD in forum Macromedia ColdFusion
    Replies: 3
    Last Post: March 4th, 07:39 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139