Solved

JS error

Posted on 2016-09-16
10
62 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

739 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