Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Jquery get value dropdownlist

Posted on 2013-12-12
2
Medium Priority
?
345 Views
Last Modified: 2013-12-12
  $(window).load(function () {
        $(function () {
            $.getJSON('@Url.Action("List", "Search")', function (result) {
                 var ddl = $('#ID');
                 ddl.empty();
                 $(result).each(function (i, item) {

                     ddl.append(
                         $('<option/>', {
                             value: this.ID
                         }).html(this.Description)

                     );
                 });
            });
          

         });

Open in new window

I am using Jquery mobile. When I first go to the page the data loads, When I click a button and leave the page then come back I see the data in my Dom but it does not load back into the dropdown. anyway to fix this.
0
Comment
Question by:Seven price
2 Comments
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 39715760
Take a look here : http://jquerymobile.com/demos/1.2.1/docs/api/events.html

So try this :
 $(document).bind('pageinit', function() {


     $.getJSON('@Url.Action("List", "Search")', function (result) {
                 var ddl = $('#ID');
                 ddl.empty();
                 $(result).each(function (i, item) {

                     ddl.append(
                         $('<option/>', {
                             value: this.ID
                         }).html(this.Description)

                     );
                 });
            });


 });

Open in new window

0
 
LVL 9

Author Closing Comment

by:Seven price
ID: 39715778
Great thanks
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

885 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