Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
iam binding the dropdown using ajax. iam set default value on dropdown bind useing selected event. if dropdown complete the bind. i want to get selected value on default. and iam change another dropdown to use of this default value on page load



thanks Regards

What I have tried:

function addSelect(divname, columname, defaultvalue,dropid, tablename, pd, userid, chartid, filte) {
var newDiv = document.createElement(pd);
var change = " onchange='dropchange(this)' ";
var html = '<select ' + change + ' title="' + defaultvalue + '" id="' + dropid + '" name = "' + columname + '" >'
var obj = {};
obj.coluname = columname;
obj.tablename = tablename;
obj.userid = userid;
obj.chartid = chartid;
obj.filte = filte;
$.ajax({
url: "webmethod.aspx/dropdownbine",
data: JSON.stringify(obj),
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function(r) {

var result = r.d;
var sel = "All";
var selected="true";
html += "<option Value='" + sel + "' title ='" + defaultvalue + "'>" + sel + "</option>";
for (i = 0; i < result.length; i++)
{
if(defaultvalue==result[i])
{
html += "<option selected='" + selected + "' value='" + result[i] + "'>" + result[i] + "</option>";
}
else {
html += "<option value='" + result[i] + "'>" + result[i] + "</option>";
}
}
html += '</select>';
newDiv.innerHTML = html;
document.getElementById(divname).appendChild(newDiv);

},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('Got an Error Dropdownlist bind ');
}
});

}





var a =$.trim($("[id*=chart0Filter2drop0]").val());
Posted
Updated 13-Sep-16 4:37am
v2

1 solution

Try :

JavaScript
var a =$.trim($("[id*=chart0Filter2drop0]  option:selected").val());
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900