Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JS error

Posted on 2016-09-16
10
Medium Priority
?
73 Views
Last Modified: 2016-09-17
Hi,

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");
                }
            }
        }
    }

Open in new window

0
Comment
Question by:mcrmg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 9

Expert Comment

by:Mukesh Yadav
ID: 41801863
There is not such error in this code?

Share complete code or share url of page to check.
0
 

Author Comment

by:mcrmg
ID: 41801877
this is inside a form

			<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=">>">

Open in new window


thanks
0
 
LVL 9

Expert Comment

by:Mukesh Yadav
ID: 41801893
Here problem is " in onclick replace it by ':

<INPUT onclick="AddListElements(this.form, 'testCategory')" type=button value=">>11">
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mcrmg
ID: 41801904
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
0
 
LVL 9

Expert Comment

by:Mukesh Yadav
ID: 41801913
Please tell us what you are trying to do?
0
 

Author Comment

by:mcrmg
ID: 41801933
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

<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>

Open in new window

0
 
LVL 9

Accepted Solution

by:
Mukesh Yadav earned 2000 total points
ID: 41801998
I think you should try this plugin instead of developing it from scratch

http://loudev.com/#demos
0
 

Author Closing Comment

by:mcrmg
ID: 41802147
Thank you
0
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 41802713
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.
0
 

Author Comment

by:mcrmg
ID: 41802958
I see.  Thanks for the direction.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question