I have written a small script just to learn how, and I can't get this to work. The validation works fine, and the initial display is fine, but when you click on the image, I get a pop-up window that tells me "Player" is undefined in my script. I suppose I'm missing some small syntax that is causing the variable to not be passed into the function, but I've been through the documentation and haven't been able to find it. Maybe another set of eyes will. Here's my entire page:
Calista :-X
Jedi Knight,
Champion of the Force
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Image Swap</TITLE>
</HEAD>
<BODY>
<!--- Set variables --->
<CFSET Player = "Red">
<CFSET CurrentImage = "GreenSquare.gif">
<!--- This is the script that actually performs the image swap. --->
<CFSCRIPT>
function SwapImage(Player)
{
if(Player EQ "Red")
CurrentImage="RedCircle.gif";
else
CurrentImage="WhiteCircle.gif";
return CurrentImage;
}
</CFSCRIPT>
<!--- Validate our input before processing. --->
<!--- Is CurrentImage defined and EQ to "GreenSquare"? --->
<CFIF NOT IsDefined("CurrentImage")>
<FONT COLOR="Purple">CurrentImage is NOT defined.</FONT><BR><BR>
<CFELSEIF #CurrentImage# EQ "GreenSquare.gif">
<FONT COLOR="Green">"CurrentImage" has been validated correctly!.</FONT><BR><BR>
<CFELSE>
<FONT COLOR="Red">"CurrentImage" is NEQ to "GreenSquare.gif"!</FONT><BR><BR>
</CFIF>
<!--- Is Player defined and EQ to "Red" or "White"? --->
<CFIF NOT IsDefined("Player")>
<FONT COLOR="Purple">Player is NOT defined.</FONT><BR><BR>
<CFELSEIF #Player# EQ "Red">
<FONT COLOR="Green">"Player" has been validated correctly!.</FONT><BR><BR>
<CFELSEIF #Player# EQ "White">
<FONT COLOR="Green">"Player" has been validated correctly!.</FONT><BR><BR>
<CFELSE>
<FONT COLOR="Red">"Player" is NEQ "Red" or "White"!</FONT><BR><BR>
</CFIF>
<CFOUTPUT>
<A HREF="ImageSwap.cfm"><IMG ONCLICK="SwapImage(Player)" SRC="#CurrentImage#" BORDER="0" ALT=""></A>
</CFOUTPUT>
</BODY>
</HTML>
Jedi Knight,
Champion of the Force