Solved

Remove alert and dropdownlist value does not get selected

Posted on 2013-10-30
3
443 Views
Last Modified: 2013-10-30
This is a continuation of a question yesterday.
I have a dropdownlist which gets populated by an JSON file and jquery, everything works great but when I enter a record and then go to the edit page to edit it.
I want the dropdown list to have the proper value selected on opening but I cannot get it to work
I got help yesterday which seemed to work perfectly
$(document).ready(function () {
    'use strict';
    $.getJSON("../../JSON/States.json", function (data) {
        var states = data.States;

        $.each(states, function (id, states) {
            $("#SelectState").append("<option value='" + states.abbreviation + "'>" + states.name + "</option>");
        });

    });
    alert($("#hidState").val());
        var hidden = $("#hidState").val();      
          $("#SelectState").val(hidden)
});

Open in new window


I put an alert in to make sure the value was coming across and it was and the dropdown list got updated and the proper value was selected (All good) So I removed the alert, but when I did the dropdown list does not get the value selected anymore. When I put in the alert everything works but when I remove it the dropdown list gets populated but the proper value is not selected.

hidState is a hidden field which gets updated by  model.State when page opens (In case that makes a difference)

Thanks again for any help
0
Comment
Question by:Niall292
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39611304
Check this :
$(document).ready(function () {
    'use strict';
    $.getJSON("../../JSON/States.json", function (data) {
        var states = data.States;

        $.each(states, function (id, states) {
            $("#SelectState").append("<option value='" + states.abbreviation + "'>" + states.name + "</option>");
        });

        var hidden = $("#hidState").val();      
        $("#SelectState").val(hidden)

    });
});

Open in new window

0
 

Author Comment

by:Niall292
ID: 39611325
Again you saved the day,
Was it just the positioning that was the problem
0
 

Author Closing Comment

by:Niall292
ID: 39611327
You make it look so easy.
Thanks again
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now