Solved

json append to second select

Posted on 2014-03-28
2
274 Views
Last Modified: 2014-03-28
Trying to append data to another dropdown after response from jquery data. but for some reason it is not displaying or get and error object

Response after selection from Getmyweek.  Json
{"messages":[{"Week":7},{"Week":8},{"Week":14}]}

Open in new window


 
<select id="Getmyweek">
          <option selected="selected">-- Please Select --</option>
  <option> week 7-</option>

      </select>
<select id="GetWeek">
      </select>

Open in new window


$("#Getmyweek").change(function () {

              
                var Id = $("#Getmyweek").val();
                $.ajax({
                    url: '@Url.Action("getcontroller", "Viewer")',
                type: "Post",
                data: { Chain1: Id },
                success: function (listItems) {
                    $.each(listItems, function (i, item) {
                        $('#GetWeek').append($('<option>').text(this.Week).attr('value', item));
                    });

                    // var toAppend = '';
                    //    $.each(listItems, function (i, item) {
                    //    toAppend += '<option>' + item + '</option>';
                    //   // alert(toAppend);
                    //});
                        $('#GetmyWeek').append(toAppend).html;
                 
                },
                error: function (xhr, ajaxOptions, error) {
                    alert(xhr.status);
                    alert('Error: ' + xhr.responseText);
                }

            });

             });

Open in new window

0
Comment
Question by:sevensnake77
[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
2 Comments
 
LVL 24

Accepted Solution

by:
mankowitz earned 500 total points
ID: 39962170
I think you want this

$.each(listItems.messages, function (i, item) {
   $('#GetWeek').append($('<option>').text(item.Week).attr('value', item));
});
0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 39962291
listItems.messages was the key thanks
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
The viewer will learn how to dynamically set the form action using jQuery.
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)

759 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