0

How to i get a value of a selected ITEM from a drop down list ? I'm reading my values a SQL Table using a Stored Procedure ,Once the list is populated i want to take the selected ITEM and save the SQL TABLE. Any help will be much appreciated. Here is what i've tried :

function QueryKomaxDetails() {
    $.ajax({
        url: GET_SCHEDULE_DEPARTMENTS,
        data: 'includeInactive=' + null,
        dataType: 'json',
        success: LoadKomaxDetails
    });
}

var LoadKomaxDetails = function (data) {
    var dllItems = eval(data);
    var komaxDetails = $("#ddlItems").val();
    $.each(dllItems, function () {
        komaxDetails.append("<option value='" + this.departmentId + "'>" + this.departmentName + "</option>");
    });
}

And i managed to get ITEM as a dropdown list. Here is my HTML code as follows :

<label>Select Komax :</label><select id="ddlItems" name="komax" ></select>
Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
IBonesh
  • 73
  • 5
  • Watch out, `eval(data)` might be a security hole if `data` can be manipulated by users. Actually, isn't jQuery will automatically change it to an Object by default? – Derek 朕會功夫 Jan 28 '14 at 06:11
  • possible duplicate of [jquery get selected option from dropdown](http://stackoverflow.com/questions/10659097/jquery-get-selected-option-from-dropdown) – Günter Zöchbauer Jan 28 '14 at 13:32

1 Answers1

0

Try this,

var komaxDetails = $("#ddlItems");
$.each(dllItems, function () {
        komaxDetails.append("<option value='" + this.departmentId + "'>" + this.departmentName + "</option>");
});
akhil.cs
  • 691
  • 1
  • 5
  • 12