Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using <cfif ...> within <cfinput ...> tag construct problem

Status
Not open for further replies.

josel

Programmer
Joined
Oct 16, 2001
Messages
716
Location
US
I am trying to use one template to work as action page for Edit/Add. The calling template passes URL variables to trigger proper behavior in action page.

Following line of code is sample of what I am using throughout the template. I commented out the first few and they all keep on returning same error.

THE LINE OF CODE LOOKS LIKE THIS:

<cfinput name=&quot;DstCode&quot; length=&quot;20&quot; maxlength=&quot;20&quot; required=&quot;yes&quot; message=&quot;You Must Enter A Code!&quot; type=&quot;text&quot; <cfif URL.Method eq &quot;EDIT&quot;>value=&quot;#getDist.DstCode#&quot;</cfif>>

I GET THIS ERROR:
------------------------------------------------
Just in time compilation error

Invalid token found on line 67 at position 70. ColdFusion was looking at the following text:

<
Invalid expression element. The usual cause of this error is a misspelling in the expression text.
The last successfully parsed CFML construct was a CFINPUT tag occupying document position (67:7) to (67:14).

---------------------------------------------------

A) I have a query named getDist
B) The URL variable exists
C) Field name matches that on table

What am I doing wrong?

Thank you all in advance;


josel
If you have the knowledge, consult and educate those who need it! - Jose Lerebours
 
OK, I just fount out that <cfinput> does not like <cfif...> within ... I changed my <cfinput> to <input> and it works fine!

But, I want to take advange of REQUIRED attribute so I changed my command to be enclosed within a <cfif><cfelse></cifif>. I guess this will require more juice from server but if this is the way it has to be, be it!

Sample of new code:

<cfif URL.Method IS &quot;EDIT&quot;><cfinput name=&quot;DstAcct&quot; length=&quot;20&quot; maxlength=&quot;20&quot; type=&quot;text&quot; value=&quot;#getDist.DstAcct#&quot; required=&quot;yes&quot; message=&quot;You Must Enter An Account Number!&quot;><CFELSE><cfinput name=&quot;DstAcct&quot; length=&quot;20&quot; maxlength=&quot;20&quot; type=&quot;text&quot; required=&quot;yes&quot; message=&quot;You Must Enter An Account Number!&quot;></CFIF>


Regards;


Jose Lerebours If you have the knowledge, consult and educate those who need it! - Jose Lerebours
 
It's not that it uses more CPU that makes it less desirable. It's that the code is harder to read and harder to maintain. A preferred way is:

<cfif URL.Method IS &quot;EDIT&quot;>
<cfset existing_text = getDist.DstAcct>
<cfelse>
<cfset existing_text = &quot;&quot;>
</cfif>

<cfinput name=&quot;DstAcct&quot;
length=&quot;20&quot;
maxlength=&quot;20&quot;
type=&quot;text&quot;
value=&quot;#existing_text#&quot;
required=&quot;yes&quot;
message=&quot;You Must Enter An Account Number!&quot;
>

In the code above, there is only one instance of the <INPUT> field. If you change anything there, you change it the same way for both cases. The <CFIF> block contains only thoses components that vary, making it easy to see what the difference between the two cases is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top