1

I was looking for a picklist template in JavaScript and came across this code.

JsFiddle for picklist

Which has the following code to parse through a from what I am assuming is a jQuery object array.

     var val = {
        01: {id: 01, text: 'test2'},
        02: {id: 02, text: 'test3'},
        03: {id: 03, text: 'test2'},
     };

     var pick = $("#pickList").pickList({data: val});

     $("#getSelected").click(function () {
        console.log(pick.getValues(val));
        alert(pick.getValues());
     });
 

Where the #pickList is a function which populates data onto a form.

Now when I run this using the button "#getSelected" , I can see in Chrome developer options that it is fetching the data from the form but in some sort of an key value pair.

Now, When I try to alert(pick.getValues());

I get an alert with [object Object] and not the value inside the array.

Can someone help me to know how to parse the array so that I can get the value of the "text"

Below is a screenshot of the Chrome dev console. Screenshot of chrome dev options

5
  • 1
    Instead of alert(pick.getValues()); use console.log(pick.getValues()); and see the console output in your dev console. Commented Oct 18, 2016 at 11:50
  • @DavidR Console.log works actually, how do I post it to the server? I was thinking if I can get it to alert then I can move the value to a variable and then post that to the server. Commented Oct 18, 2016 at 11:52
  • Then try this alert(JSON.stringify(pick.getValues())) Commented Oct 18, 2016 at 11:52
  • @DavidR Wow that works. Can you post that as an answer so that i can mark it as solved? THank you so much Commented Oct 18, 2016 at 11:54
  • Done mate!. Thanks! Commented Oct 18, 2016 at 11:55

1 Answer 1

1

You need to use JSON.stringify inside your alert statement like this,

alert(JSON.stringify(pick.getValues()));

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.