<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Fred Travels</title> <script src="jquery.min.js"></script> <script> $(document).ready(function () { //page load $.ajax({ type: "GET", url: "http://localhost:2160/CustomerService.svc/CustomerTypeSelect", contentType: "application/json; charset=utf-8", data: {}, dataType: "json", processData: true, success: function (data, status, jqXHR, result) { if (data.length > 0) { var $el = $("#ddlCustType"); $el.empty(); // remove old options $el.append($("<option></option>").attr("value", 0).text('Please Select')); for (var i = 0; i < data.length; i++) { $el.append($("<option></option>").attr("value", data[i].CusTypeID).text(data[i].CustTypeName)); } } } }); CustomerSelectviaID(1); }); function CustomerSelectviaID(CustID) { var Customer = { rowno: 1, TotalRecords: 5, CustomerID: CustID }; $.ajax({ type: "POST", url: "http://localhost:2160/CustomerService.svc/CustomerSelect", data: JSON.stringify(Customer), contentType: "application/json; charset=utf-8", dataType: "json", processData: true, success: function (data, status, jqXHR, result) { if (data.length > 0) { alert("test"); $('#ddlCustType').val(data[0].Type); return false; } } }); $('#hdnCustID').val(CustID); } </script> </head> <body> <div> <select id="ddlCustType" class="form-control"> <option value="0">Please Select</option> <option value="1">Corporate</option> <option value="2">Tour Operator</option> <option value="3">Direct Customer</option> <option value="4">out source</option> </select> </div> </body> </html>
text
val('value')
var text = data[0].Type; $("#ddlCustType option").filter(function () { return this.text == text1; }).attr('selected', true);
alert
Id
Text
undefined
$("#ddlCustType option:selected").text();
$("#ddlCustType option:selected").val();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)