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

CFSCRIPT not receiving variable

Status
Not open for further replies.

calista

Programmer
Jan 24, 2001
545
US
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:
Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<HTML>
<HEAD>
	<TITLE>Image Swap</TITLE>

</HEAD>

<BODY>

<!--- Set variables --->
<CFSET Player = &quot;Red&quot;>
<CFSET CurrentImage = &quot;GreenSquare.gif&quot;>

<!--- This is the script that actually performs the image swap. --->
<CFSCRIPT>
function SwapImage(Player)
	{
	if(Player EQ &quot;Red&quot;)
    	CurrentImage=&quot;RedCircle.gif&quot;;
  	else
    	CurrentImage=&quot;WhiteCircle.gif&quot;;
	return CurrentImage;
	}
</CFSCRIPT>

<!--- Validate our input before processing. --->
<!--- Is CurrentImage defined and EQ to &quot;GreenSquare&quot;? --->
<CFIF NOT IsDefined(&quot;CurrentImage&quot;)>
	<FONT COLOR=&quot;Purple&quot;>CurrentImage is NOT defined.</FONT><BR><BR>
	<CFELSEIF #CurrentImage# EQ &quot;GreenSquare.gif&quot;>
		<FONT COLOR=&quot;Green&quot;>&quot;CurrentImage&quot; has been validated correctly!.</FONT><BR><BR>
<CFELSE>
	<FONT COLOR=&quot;Red&quot;>&quot;CurrentImage&quot; is NEQ to &quot;GreenSquare.gif&quot;!</FONT><BR><BR>
</CFIF>

<!--- Is Player defined and EQ to &quot;Red&quot; or &quot;White&quot;? --->
<CFIF NOT IsDefined(&quot;Player&quot;)>
	<FONT COLOR=&quot;Purple&quot;>Player is NOT defined.</FONT><BR><BR>
	<CFELSEIF #Player# EQ &quot;Red&quot;>
		<FONT COLOR=&quot;Green&quot;>&quot;Player&quot; has been validated correctly!.</FONT><BR><BR>
		<CFELSEIF #Player# EQ &quot;White&quot;>
			<FONT COLOR=&quot;Green&quot;>&quot;Player&quot; has been validated correctly!.</FONT><BR><BR>
<CFELSE>
	<FONT COLOR=&quot;Red&quot;>&quot;Player&quot; is NEQ &quot;Red&quot; or &quot;White&quot;!</FONT><BR><BR>
</CFIF>

<CFOUTPUT>
<A HREF=&quot;ImageSwap.cfm&quot;><IMG ONCLICK=&quot;SwapImage(Player)&quot; SRC=&quot;#CurrentImage#&quot; BORDER=&quot;0&quot; ALT=&quot;&quot;></A>
</CFOUTPUT>

</BODY>
</HTML>
Calista :-X
Jedi Knight,
Champion of the Force
 
OK, here's the next version. I still get the pop-up window, only now it's telling me 'Red' is undefined. In addition, I don't get any output from the WriteOutputs in my script, so maybe it's not even getting that far. I'm getting a little frustrated with this, because I can't seem to get even a very simple script to work. ARRRGHHH!!! :-(
Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<HTML>
<HEAD>
	<TITLE>Image Swap</TITLE>
<!--- This is the script that actually performs the image swap. --->
<CFSCRIPT>
function SwapImage(Player)
	{
	WriteOutput(Player);
	Color=&quot;Red&quot;;
	WriteOutput(Color);
	if(Player EQ Color)
    	CurrentImage=&quot;RedCircle.gif&quot;;
  	else
    	CurrentImage=&quot;WhiteCircle.gif&quot;;
	return CurrentImage;
	}
</CFSCRIPT>
</HEAD>

<BODY>

<!--- Set variables --->
<CFSET Player = &quot;Red&quot;>
<CFSET CurrentImage = &quot;GreenSquare.gif&quot;>

<!--- Validate our input before processing. --->
<!--- Is CurrentImage defined and EQ to &quot;GreenSquare&quot;? --->
<CFIF NOT IsDefined(&quot;CurrentImage&quot;)>
	<FONT COLOR=&quot;Purple&quot;>CurrentImage is NOT defined.</FONT><BR><BR>
	<CFELSEIF #CurrentImage# EQ &quot;GreenSquare.gif&quot;>
		<FONT COLOR=&quot;Green&quot;>&quot;CurrentImage&quot; has been validated correctly!.</FONT><BR><BR>
<CFELSE>
	<FONT COLOR=&quot;Red&quot;>&quot;CurrentImage&quot; is NEQ to &quot;GreenSquare.gif&quot;!</FONT><BR><BR>
</CFIF>

<!--- Is Player defined and EQ to &quot;Red&quot; or &quot;White&quot;? --->
<CFIF NOT IsDefined(&quot;Player&quot;)>
	<FONT COLOR=&quot;Purple&quot;>Player is NOT defined.</FONT><BR><BR>
	<CFELSEIF #Player# EQ &quot;Red&quot;>
		<FONT COLOR=&quot;Green&quot;>&quot;Player&quot; has been validated correctly!.</FONT><BR><BR>
		<CFELSEIF #Player# EQ &quot;White&quot;>
			<FONT COLOR=&quot;Green&quot;>&quot;Player&quot; has been validated correctly!.</FONT><BR><BR>
<CFELSE>
	<FONT COLOR=&quot;Red&quot;>&quot;Player&quot; is NEQ &quot;Red&quot; or &quot;White&quot;!</FONT><BR><BR>
</CFIF>

<CFOUTPUT>
<A HREF=&quot;ImageSwap.cfm&quot;><IMG ONCLICK=&quot;SwapImage(#Player#)&quot; SRC=&quot;#CurrentImage#&quot; BORDER=&quot;0&quot; ALT=&quot;&quot;></A>
</CFOUTPUT>

</BODY>
</HTML>
Just for additional FYI, the following script works as a stand-alone.
Code:
<CFSCRIPT>
 	Color=&quot;Red&quot;;
	Player=&quot;Red&quot;;
	WriteOutput(Color);
	WriteOutput(Player);
	if(Player EQ Color)
    	CurrentImage=&quot;RedCircle.gif&quot;;
  	else
    	CurrentImage=&quot;WhiteCircle.gif&quot;;
	WriteOutput(CurrentImage);
</CFSCRIPT>
Calista :-X
Jedi Knight,
Champion of the Force
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top