且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获取下拉列表中的下拉值

更新时间:2022-10-26 10:20:50

.ajax({

url:webmethod.aspx / dropdownbine,

数据:JSON.stringify(obj),

dataType:json,

类型:POST,

contentType:application / json; charset = utf-8,

成功:功能(r){



var result = rd;

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);



},

错误:函数(XMLHttpRequest,textStatus,errorThrown){

alert('得到错误下拉列表绑定');

}

} );



}











var a =


.trim(


([id * = chart0Filter2drop0])VAL());

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());

.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());