facebook

Set Combo Box Value

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #336065 Reply

    Pablo22
    Member

    This is driving me nuts!
    I have a combo box that I populate from a web service that returns a JSON encoded string as follows…

    function doGetCountries() {
    //Clear Country drop down
    $(‘#m1-pCheckIn-hidden-select-cCountry’).empty();

    //Set up AJAX and fill Country drop down
    var webURL = “http://www.xxxxxxxx.com/xxxxxxxx/xxxxxxxxx.asmx/GetCountryList”;
    $.ajax({
    type: “POST”,
    url: webURL,
    contentType: “application/json”,
    dataType: “json”,
    success: function(jSON) {
    var webJSON = jSON.d;
    var webData = webJSON.split(‘;’);
    //Parse array into combo
    for (var iCount = 2; iCount < webData.length; iCount++) {
    $(‘select[name=”cCountry”]’).append( new Option(webData[iCount],webData[iCount]));
    }
    },
    error: function(e){
    $(‘#m1-pCheckIn-cTest’).val(‘GetCountryList method failed’);
    }
    });

    //End
    $(‘select[name=”cCountry”] option[value=”Argentina”]’).attr(‘selected’,’selected’) ;
    phoneui.preprocessDOM(‘#m1-pCheckIn’);
    return;
    }
    The combo box populates correctly.
    The problem is that no matter what method I use whether it be..
    $(‘select[name=”cCountry”] option[value=”Argentina”]’).attr(‘selected’,’selected’) ;
    phoneui.preprocessDOM(‘#m1-pCheckIn’);
    or
    $(‘select[name=”cCountry”]’).val(“Argentina”);
    The combo box ALWAYS has the first list value selected (which is Afghanistan) and ‘Argentina’ is in the list.

    HELP!!!

    #336066 Reply

    Brandon
    Member

    Just a thought but if are populating it with the same info each time maybe use something like this:

    //select the nth option in list
    $('select[name="combobox1"] option:eq(2)').attr('selected','selected')
    phoneui.preprocessDOM('#screenId'); //force UI to update

    If the options changes, but the above works, you could also check which index value Argentina is and use that in the code later…

    #336153 Reply

    Hi Pablo,

    I did a simple test with your code in a new file with just a combobox and it worked fine. Which make me think about two possible reasons that it is not working for you:

    *Your combobox has a different name
    *There is no value for a item in the combobox that match with “Argentina”

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: Set Combo Box Value

You must be logged in to post in the forum log in