A very weird JS error :-)

K

Keiron Waites

Ok to understand what I'm doing you'll have to load the HTML file attached
(code also below):

When you select an item on the left and select the ">>" button, some alerts
will come up telling you what's happening. The first 2 alerts will tell you
which items are being added to the array arrayFbox. arrayFbox is a
multidimensional array. The values being added are the 2 items that you did
not select from the left box.

Next, you will get an alert telling you that 2 items are in arrayFbox
(arrayFbox.length).

Finally, two more alerts will come up as the script loops through arrayFbox
to check it. Here is where the error is first seen! If you select People or
Cartoon both values in the array will be array(5,Garden) or if you select
Garden both values will be array(4,cartoon).

Please tell me why this is happening! I'm pulling my hair out!!

Thanks,

Keiron

The code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Fucking Work!!!</title>
</head>

<body>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
// fbox = option moved from, tbox = option moved to.
function move (fbox,tbox) {
var arrayFbox = new Array();
var arrayFboxInside = new Array();
var arrayTbox = new Array();
var arrayTboxInside = new Array();
var i;
var j;
var x;
j = 0;
x = 0;
// Create the original fbox list in an array, minus the
value moved.
for (i = 0; i < fbox.options.length; i++) {
// The items moved.
if (fbox.options.selected) {
arrayTboxInside[0] = fbox.options.value;
arrayTboxInside[1] = fbox.options.text;
if ((tbox.options.length == 1) &&
(tbox.options[0].value == "")) {
arrayTbox[0] = arrayTboxInside;
}
else {
arrayTbox[tbox.options.length+x] =
arrayTboxInside;
}
x++;
arrayTboxInside.splice(0);
}
// The items not moved.
else {
arrayFboxInside[0] = fbox.options.value;
arrayFboxInside[1] = fbox.options.text;
arrayFbox[j] = arrayFboxInside;
arrayFboxInside.splice(0);
alert("arrayFbox["+j+"] values as I add them
to arrayFbox: "+arrayFbox[j][0]+", "+arrayFbox[j][1]);
j++;
}
}
alert("arrayFbox Length: "+arrayFbox.length);
for (i=0; i < arrayFbox.length; i++) {
alert("arrayFbox["+i+"] values after I have finished
adding them to arrayFbox: "+arrayFbox[0]+", "+arrayFbox[1]);
}
}
// -->
</script>

<form name="form" method="post" action="customer-content.php?add">
<table cellspacing="0" cellpadding="5">
<tr>
<td class="main_body"><select
name="list1" multiple style="width:150; height: 150;"
onchange="document.form.list2.selectedIndex='-1';">

<option value="3">People</option>

<option value="4">Cartoon</option>

<option value="5">Garden</option>

</select>
</td>
<td align="center"><input
type="button" value=" &gt;&gt; "
onClick="move(this.form.list1,this.form.list2)"><br>
<input type="button" value="
&lt;&lt; " onClick="move(this.form.list2,this.form.list1)"></td>
<td><select name="list2" multiple
style="width:150; height: 150;" onchange="list_content.innerHTML='<img
src=images/customer_images/thumb-'+imageDetails[this.form.list1.selectedInde
x]+' border=1><br>'+imageTitles[this.form.list2.selectedIndex];
document.form.list1.selectedIndex='-1';"></select></td>
</tr>
</table>
</form>



</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top