how to set values to combobox dynamically in javascript
Posted
by
Learner
on Stack Overflow
See other posts from Stack Overflow
or by Learner
Published on 2012-09-17T08:57:29Z
Indexed on
2012/09/17
9:37 UTC
Read the original article
Hit count: 285
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
© Stack Overflow or respective owner