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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

align= variable -- How?

Status
Not open for further replies.

NoWayIsThisInUse

IS-IT--Management
Jul 16, 2002
79
US
What's the most efficient way to have the align= be either 'center' or 'right' depending on whether the value is a number or text? I want numbers right aligned and "None found" to be centered, for example.

<td bgcolor='##EEEEEE' align='right' width='100'>#MaybeANumberMaybeText#</td>
 
<td bgcolor='##EEEEEE' align='<cfif isnumeric(#maybeanumbermaybetext#)>right<cfelse>center</cfif>' width='100'>#MaybeANumberMaybeText#</td>

A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
oops. that would work but i just copied and pasted. here is better practice

you could also write a UDF if you're using cf 5 or better.

<td bgcolor='##EEEEEE' align='<cfif isnumeric(maybeanumbermaybetext)>right<cfelse>center</cfif>' width='100'>#MaybeANumberMaybeText#</td>

A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
Code:
<cfscript>
function setAlign(var){
 if(isNumeric(var)){
  return "Right"
 }
 else
 {
  return "Center"
 }
}
</cfscript>

<td bgcolor='##EEEEEE' align='#setAlign(MaybeANumberMaybeText)#' width='100'>#MaybeANumberMaybeText#</td>


A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top