I'm trying to learn JavaScript to apply it to my CF pages. What I'm trying to do here is a simple image swap. It works fine except for one minor detail: The script executes BEFORE anything is clicked. Help anybody? Here it is in its entirety:
Calista :-X
Jedi Knight,
Champion of the Force
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Image Swap Three</TITLE>
<!--- Set Variables --->
<CFSET CurrentSquare = "GreenSquare.gif">
<CFSET ImageOne = "GreenSquare.gif">
<CFSET ImageTwo = "RedCircle.gif">
<CFSET ImageThree = "WhiteCircle.gif">
<CFSET Player = "White">
<SCRIPT LANGUAGE = "JavaScript">
<!-- Hide from other browsers
function SwapImage()
{
<CFIF #CurrentSquare# EQ #ImageOne#>
<CFIF #Player# EQ 'Red'>
<CFSET CurrentSquare = "#ImageTwo#">
</CFIF>
<CFIF #Player# EQ 'White'>
<CFSET CurrentSquare = "#ImageThree#">
</CFIF>
<CFELSE>
alert("There has been an error!")
</CFIF>
}
// Stop Hididng from other Browsers -->
</SCRIPT>
</HEAD>
<BODY>
<CFOUTPUT>
<FORM ACTION="#CGI.SCRIPT_NAME#" METHOD="post" ENCTYPE="multipart/form-data">
<INPUT TYPE="Image" NAME="Square1_1" SRC="#CurrentSquare#" ONCLICK="SwapImage()">
</FORM>
</CFOUTPUT>
</BODY>
</HTML>
Jedi Knight,
Champion of the Force