[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Remove alert and dropdownlist value does not get selected

Posted on 2013-10-30
3
Medium Priority
?
453 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 83

Accepted Solution

by:
leakim971 earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…
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
Course of the Month20 days, 10 hours left to enroll

868 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