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
multidimensiona l 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.leng th).
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>Fuckin g Work!!!</title>
</head>
<body>
<SCRIPT LANGUAGE="JavaS cript" 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.le ngth; i++) {
// The items moved.
if (fbox.options[i].selected) {
arrayTboxInside[0] = fbox.options[i].value;
arrayTboxInside[1] = fbox.options[i].text;
if ((tbox.options. length == 1) &&
(tbox.options[0].value == "")) {
arrayTbox[0] = arrayTboxInside ;
}
else {
arrayTbox[tbox.options.le ngth+x] =
arrayTboxInside ;
}
x++;
arrayTboxInside .splice(0);
}
// The items not moved.
else {
arrayFboxInside[0] = fbox.options[i].value;
arrayFboxInside[1] = fbox.options[i].text;
arrayFbox[j] = arrayFboxInside ;
arrayFboxInside .splice(0);
alert("arrayFbo x["+j+"] values as I add them
to arrayFbox: "+arrayFbox[j][0]+", "+arrayFbox[j][1]);
j++;
}
}
alert("arrayFbo x Length: "+arrayFbox.len gth);
for (i=0; i < arrayFbox.lengt h; i++) {
alert("arrayFbo x["+i+"] values after I have finished
adding them to arrayFbox: "+arrayFbox[i][0]+", "+arrayFbox[i][1]);
}
}
// -->
</script>
<form name="form" method="post" action="custome r-content.php?add ">
<table cellspacing="0" cellpadding="5" >
<tr>
<td class="main_bod y"><select
name="list1" multiple style="width:15 0; height: 150;"
onchange="docum ent.form.list2. selectedIndex='-1';">
<option value="3">Peopl e</option>
<option value="4">Carto on</option>
<option value="5">Garde n</option>
</select>
</td>
<td align="center"> <input
type="button" value=" >> "
onClick="move(t his.form.list1, this.form.list2 )"><br>
<input type="button" value="
<< " onClick="move(t his.form.list2, this.form.list1 )"></td>
<td><select name="list2" multiple
style="width:15 0; height: 150;" onchange="list_ content.innerHT ML='<img
src=images/customer_images/thumb-'+imageDetails[this.form.list1 .selectedInde
x]+' border=1><br>'+ imageTitles[this.form.list2 .selectedIndex];
document.form.l ist1.selectedIn dex='-1';"></select></td>
</tr>
</table>
</form>
</body>
</html>
(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
multidimensiona l 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.leng th).
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>Fuckin g Work!!!</title>
</head>
<body>
<SCRIPT LANGUAGE="JavaS cript" 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.le ngth; i++) {
// The items moved.
if (fbox.options[i].selected) {
arrayTboxInside[0] = fbox.options[i].value;
arrayTboxInside[1] = fbox.options[i].text;
if ((tbox.options. length == 1) &&
(tbox.options[0].value == "")) {
arrayTbox[0] = arrayTboxInside ;
}
else {
arrayTbox[tbox.options.le ngth+x] =
arrayTboxInside ;
}
x++;
arrayTboxInside .splice(0);
}
// The items not moved.
else {
arrayFboxInside[0] = fbox.options[i].value;
arrayFboxInside[1] = fbox.options[i].text;
arrayFbox[j] = arrayFboxInside ;
arrayFboxInside .splice(0);
alert("arrayFbo x["+j+"] values as I add them
to arrayFbox: "+arrayFbox[j][0]+", "+arrayFbox[j][1]);
j++;
}
}
alert("arrayFbo x Length: "+arrayFbox.len gth);
for (i=0; i < arrayFbox.lengt h; i++) {
alert("arrayFbo x["+i+"] values after I have finished
adding them to arrayFbox: "+arrayFbox[i][0]+", "+arrayFbox[i][1]);
}
}
// -->
</script>
<form name="form" method="post" action="custome r-content.php?add ">
<table cellspacing="0" cellpadding="5" >
<tr>
<td class="main_bod y"><select
name="list1" multiple style="width:15 0; height: 150;"
onchange="docum ent.form.list2. selectedIndex='-1';">
<option value="3">Peopl e</option>
<option value="4">Carto on</option>
<option value="5">Garde n</option>
</select>
</td>
<td align="center"> <input
type="button" value=" >> "
onClick="move(t his.form.list1, this.form.list2 )"><br>
<input type="button" value="
<< " onClick="move(t his.form.list2, this.form.list1 )"></td>
<td><select name="list2" multiple
style="width:15 0; height: 150;" onchange="list_ content.innerHT ML='<img
src=images/customer_images/thumb-'+imageDetails[this.form.list1 .selectedInde
x]+' border=1><br>'+ imageTitles[this.form.list2 .selectedIndex];
document.form.l ist1.selectedIn dex='-1';"></select></td>
</tr>
</table>
</form>
</body>
</html>
Comment