?
Solved

Remove alert and dropdownlist value does not get selected

Posted on 2013-10-30
3
Medium Priority
?
450 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
[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
3 Comments
 
LVL 82

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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

762 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