I cannot for the life of me figure out why my incrementation of an Array coordinate will not increment just a single value. This is a stripped down version of the entire document, but all of the info is here that you need to evaluate. This an ASP application. I am passing VBScript variable values to javascript for user manipulation.
<head>
<script language=”JavaScript” type=”text/javascript”>
//create var for debugging
var debug = 1;
/*create array for holding coordinates to hold a value representative
of a grid of values to use in displaying different image states manipulated by user-click.
var pegIncrement = new Array(10,4);
for (i=0;i<10;i++){
for (j=0;j<4;j++){
pegIncrement[i,j] = 0;
}
}
/*create a function for grabbing the name of the image placeholder and changing it’s source to another value
function changePeg(pegPosition){
//find the name of the image and split the x,y values
incrementCords = pegPosition.split(“|”)
//condition for starting back over after 6 increments
if (pegIncrement[incrementCords[1],incrementCords[2]] == 7){
pegIncrement[incrementCords[1],incrementCords[2]] = 0;
}
/*change the .src of the image to the array() value representatvie of a relative image path references which are not present in this script
document.images[pegPosition].src = arJSPegColors[pegIncrement[incrementCords[1],incrementCords[2]]];
//increment the array value-this is where the problem is
pegIncrement[incrementCords[1],incrementCords[2]]++
//the following is for testing
if (debug == 1){
writeCords = “”
for (i=0;i<10;i++){
for (j=0;j<4;j++){
writeCords += pegIncrement[i,j]
if (j!=3){
writeCords += ” | “;
}
}
writeCords += ‘n’;
}
document.test.cords.value = writeCords;
}
}
</script>
</head>
<body>
<%
Response.Write(“<img src=’empty.gif’ name=’img|” & j & “|” & k & “‘ onClick=’changePeg(this.name);’>”)
%>
<br>
<form name=”test”>
<textarea name=”cords” cols=”20″ rows=”15″></textarea>
</form>
The textarea maps out the contents of the pegIncrement Array(). This is what is displayed when any one image is clicked in the second column of images…
0 | 1 | 0 | 0
0 | 1 | 0 | 0
0 | 1 | 0 | 0
0 | 1 | 0 | 0
0 | 1 | 0 | 0
0 | 1 | 0 | 0
0 | 1 | 0 | 0
0 | 1 | 0 | 0
0 | 1 | 0 | 0
0 | 1 | 0 | 0
It is changing the value across the entire column insted of just on ordinate. It should look like this…
0 | 0 | 0 | 0
0 | 0 | 0 | 0
0 | 0 | 0 | 0
0 | 0 | 0 | 0
0 | 0 | 0 | 0
0 | 1 | 0 | 0
0 | 0 | 0 | 0
0 | 0 | 0 | 0
0 | 0 | 0 | 0
0 | 0 | 0 | 0
each value should be independant of one another. I think it’s here where the problem is…
pegIncrement[incrementCords[1],incrementCords[2]]++
I just don’t understand why incrementing one value would loop and increment the entire column.
Anyone have any suggestions? Need more info? Thanks, Y’all
chromahoen