0

i try to use SQLite with to create dynamic dropdown list. my sql tabels are COUNTRY, COUNTRY_DISTRICT and DISTRICT. COUNTRY tabel have c1 and c2. DISTRICT table have d1,d2,d3,d4. COUNTRY_DISTRICT gave a pair (c1,d1),(c1,d2),(c1,d3) and (c2,d4). now i select c1 in country dropdown and d1 in district dropdown. after that i change selection in country to c2. my district dropdown still show as d1 but i wan is to be empty string. Thank

$(document).ready(function () {
    $("#country").change(function () {
        Country = $(this).val();
        $('#district option:eq(0)').attr('selected','selected');
        db.transaction(ChangeCountry, errorCB, sucessCB);
    });
});

function ChangeCountry(tx) {
    tx.executeSql('SELECT d.* FROM COUNTRY_DISTRICT as cd , DISTRICT as d WHERE cd.country=? and cd.district = d.district', [Country], renderDistrictList, errorCB);

}
function renderDistrictList(tx, results) {
    var len = results.rows.length;
    var htmlstring = "<option value=\"\" > </option>";


    for (var i = 0; i < len; i++) {

        htmlstring += "<option value=\"" + results.rows.item(i).district + "\">" + results.rows.item(i).district + "</option>";

    }
    $('#district').empty().append(htmlstring);
}
2
  • That's because you always select option 1 => $('#district option:eq(0)').attr('selected','selected');
    – lshettyl
    Jul 27, 2015 at 11:31
  • no i want is to return to option 1 which is empty string but i not return to it
    – khunjuice
    Jul 28, 2015 at 10:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.