Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  54] [ 5]  / answers: 1 / hits: 47449  / 12 Years ago, mon, september 17, 2012, 12:00:00

this is how i set value to a combobox using dwr call,



var reportID = '<%=reportid%>';
var reportName = '<%=reportname%>';
loadReportNames(reportUserID);



function loadReportNames(reportUserID){
CustomiseReportAction.getReportNames(reportUserID, addReportNamesDropDown);
}
function addReportNamesDropDown(resultMap){
dwr.util.removeAllOptions(reportnames);
dwr.util.addOptions(reportnames,resultMap);
}


after loading the combo box i set values to loaded combo like this,



document.getElementById(reportnames).value=reportID;


but the reportID is not set,



what could be the problem please help me to resolve this.



UPDATE :

function addCombo() {
var reportID = '<%=reportid%>';
var reportName = '<%=reportname%>';
var textb = document.getElementById(reportnames);

var option = document.createElement(option);
option.text = reportName;
option.value = reportID;
option.selected=selected;
try {
textb.add(option, null); //Standard
}catch(error) {
textb.add(option); // IE only
}
textb.value = ;
}


used above method it gives me no exception but no results.



Regards


More From » html

 Answers
31

I have not removed the value rather i added the following code, it solved me the problem.



function addCombo() {
var reportID = '<%=reportid%>';
var options= document.getElementById('reportnames').options;
for (var i= 0, n= options.length; i < n ; i++) {
if (options[i].value==reportID) {
document.getElementById(reportnames).selectedIndex = i;
break;
}
}
}

[#83055] Friday, September 14, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dylondaytond

Total Points: 92
Total Questions: 88
Total Answers: 96

Location: China
Member since Fri, Jan 15, 2021
3 Years ago
dylondaytond questions
Tue, Jun 22, 21, 00:00, 3 Years ago
Thu, May 7, 20, 00:00, 4 Years ago
;