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!

Stupid Comparison Problem

Status
Not open for further replies.

nohandlesleft254

IS-IT--Management
Apr 19, 2006
58
GB
Hi,

Can anyone explain why im such a muppet!? this keeps running the 'else' regardless...

* AddItem.Depth is a input text field
* TotalPrice is set at start of function

Thanks

if (AddItem.Depth != <cfoutput>#FindItems.Depth#</cfoutput>)
{
// If the depth has been reduced
if (AddItem.Depth < <cfoutput>#FindItems.Depth#</cfoutput>)
{
TotalPrice = (TotalPrice+25)
}
else if (AddItem.Depth > <cfoutput>#FindItems.Depth#</cfoutput> && AddItem.Depth < <cfoutput>#FindItems.Depth#</cfoutput>+100)
{
TotalPrice = (TotalPrice+10.50+6)
}
else
{
TotalPrice = (TotalPrice+60)
}
}
 
Try this: give them a quote...
>if (AddItem.Depth != <cfoutput>#FindItems.Depth#</cfoutput>)
[tt]if (AddItem.Depth != [red]"[/red]<cfoutput>#FindItems.Depth#</cfoutput>[red]"[/red])[/tt]
and hope for no quote collision. Same for other instances.
 
He's adding 100 to that and using < and >. I guess it's a number, wherever it comes from.

Cheers,
Dian
 
Hi,

Thanks guys - No effect though....

Not to great with javascript (as you might have guessed), the additem.depth and the finditems.depth(coldfusion variable) should both be numbers, in JS can i sort of 'CAST' these as numbers? or is that not likely to be the issue?
 
Can always try parseInt() (supposedly integer).
[tt]if (AddItem.Depth != parseInt("<cfoutput>#FindItems.Depth#</cfoutput>",10))[/tt]

 
Thanks again, but still no effect - so what ive done looks like it should work? I cant see why it wont if syntax etc is correct as coldfusion code is parsed first leaving the numerical values in the JS code when passed to browser... any other ideas?

 
Use (right-click) view-source to inspect what user agent sees. That's a valid first step for debugging.
 
Good Point!
Below is what the parsed JS looks like...

// Check if the Width doesnt equal the standard width
if (AddItem.Depth != 560)
{
// If the depth has been reduced
if (AddItem.Depth <560)
{
TotalPrice = (TotalPrice+25)
}
else if (AddItem.Depth > 560 && AddItem.Depth <560+100)
{
TotalPrice = (TotalPrice+10.50+6)
}
else if (AddItem.Depth > 560 && AddItem.Depth <560+200)
{
TotalPrice = (TotalPrice+10.50+6)
}
else
{
TotalPrice = (TotalPrice+60)
}
}
 
Watch out non-printable character(s) which might slip into the cfoutput. The easiest way to discover this aspect is to use escape().
[tt] if (AddItem.Depth != escape("<cfoutput>#FindItems.Depth#</cfoutput>"))[/tt]
Invoke viewsource again and watch what it shows.

 
Correction:

I shouldn't say put escape in the condition, I should rather said inside the function, put an alert line.

[tt] [blue]alert(escape("<cfoutput>#FindItems.Depth#</cfoutput>"));[/blue]
if (AddItem.Depth != <cfoutput>#FindItems.Depth#</cfoutput>)
{ //etc etc continuing...
[/tt]
 
What if you put your cold fusion value into a JS variable to reduce confusion?
Code:
newdepth = <cfoutput>#FindItems.Depth#</cfoutput> ;
if (AddItem.Depth != newdepth)
etc.
 
just to be clear, I'd also put some of the more complex statements into their own brackets to make the logic easier and ensure consistency e.g.:

else if (AddItem.Depth > 560 && AddItem.Depth <560+100)

becomes :

else if ((AddItem.Depth>560) && (AddItem.Depth<(560+100)))



Greg Griffiths
Livelink Certified Developer & ECM Global Star Champion 2005
 
Hi Guys,

Thanks for all your help - ending up organising the code as ggriffit suggested, and somewhere along the way it started working! - so thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top