mcrmg
asked on
JS error
Hi,
When I run the following code, I received the error
test.aspx:15 Uncaught SyntaxError: Unexpected token }
Any ideas? thanks
When I run the following code, I received the error
test.aspx:15 Uncaught SyntaxError: Unexpected token }
Any ideas? thanks
function AddListElements(frm, list) {
if (list.length != 0) {
var eArray = new Array();
var tArray = new Array();
//looks for all the selects on the left side that contains selected items
for (var j = list.length - 1; j >= 0; j--) {
value = list.options[j].value;
text = list.options[j].text;
eArray[countElements] = value;
tArray[countElements] = text;
if (!isInArray(value, lArray)) {
lArray[countElements][0] = list.options[j].value;
lArray[countElements][1] = list.name;
lArray[countElements][2] = 1;
lArray[countElements][3] = list.options[j].text;
}
RemoveOption(list, j);
DecrementIndexes(list.name);
countElements++;
}
for (var j = eArray.length - 1; j >= 0; j--) {
if (eArray[j] != null) {
AddOption(frm.mainlist, eArray[j], tArray[j]);
eArray[j] = null;
tArray[j] = null;
IncrementIndexes("mainlist");
}
}
}
}
ASKER
this is inside a form
thanks
<SELECT multiple size="7" name="testCategory" >
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</SELECT>
<INPUT onclick="AddListElements(this.form,"testCategory")" type=button value=">>">
thanks
Here problem is " in onclick replace it by ':
<INPUT onclick="AddListElements(t his.form, 'testCategory')" type=button value=">>11">
<INPUT onclick="AddListElements(t
ASKER
Thank you very much
When I show alert(list.length);, it shows 12, why does it show 12? I thought there are only 4?
then the error shows
Uncaught TypeError: Cannot read property '11' of undefined
I am sorry if the answer is too obvious. thanks
When I show alert(list.length);, it shows 12, why does it show 12? I thought there are only 4?
then the error shows
Uncaught TypeError: Cannot read property '11' of undefined
I am sorry if the answer is too obvious. thanks
Please tell us what you are trying to do?
ASKER
sorry about that. here is the code. When I select items from the left and press ">>", the slected items should go to the right side.
I am getting "Uncaught TypeError: Cannot read property '11' of undefined"
thanks
I am getting "Uncaught TypeError: Cannot read property '11' of undefined"
thanks
<form name="form1">
<SELECT multiple size="7" name="testCategory" >
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</SELECT>
<INPUT onclick="AddListElements(this.form,'testCategory')" type=button value=">>">
<SELECT CLASS="AdHoc_Form_RIGHT" multiple size=17 name=mainlist></SELECT>
</form>
<script>
function AddListElements(frm, list) {
if (list.length != 0) {
var eArray = new Array();
var tArray = new Array();
//looks for all the selects on the left side that contains selected items
for (var j = list.length - 1; j >= 0; j--) {
value = list.options[j].value;
text = list.options[j].text;
eArray[countElements] = value;
tArray[countElements] = text;
if (!isInArray(value, lArray)) {
lArray[countElements][0] = list.options[j].value;
lArray[countElements][1] = list.name;
lArray[countElements][2] = 1;
lArray[countElements][3] = list.options[j].text;
}
RemoveOption(list, j);
DecrementIndexes(list.name);
countElements++;
}
for (var j = eArray.length - 1; j >= 0; j--) {
if (eArray[j] != null) {
AddOption(frm.mainlist, eArray[j], tArray[j]);
eArray[j] = null;
tArray[j] = null;
IncrementIndexes("mainlist");
}
}
}
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you
list is a string - you are passing the string 'testCategory' to the function - not the actual control.
Therefore, when you do list.length it is giving you the length of the string 'testCategory' - not the length of the list.
Therefore, when you do list.length it is giving you the length of the string 'testCategory' - not the length of the list.
ASKER
I see. Thanks for the direction.
Share complete code or share url of page to check.