Click here to Skip to main content
15,896,498 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
iam creating dynamic dropdown with onchange event. how i get dropdown id on onchange function

What I have tried:

function addSelect(divname, columname, dropid, tablename,pd) {
var newDiv = document.createElement(pd);
var change = "dropchange(" + dropid + ")";
var html = '<select id="' + dropid + '" >'
var obj = {};
obj.coluname = columname;
obj.tablename = tablename;
$.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 = "SELECT"
html += "<option Value='" + sel + "'>" + sel + "</option>";
for (i = 0; i < result.length; i++)
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 ');
}
});

}


function dropchange(id) {
alert(id.value);
}
Posted
Updated 17-Aug-16 21:04pm

1 solution

try this

JavaScript
var change = " onchange='dropchange(this)' ";
        var html = '<select ' + change + '  id="' + dropid + '" >'

JavaScript
function dropchange(drp) {
           alert(drp.id);
           alert(drp.value);
       }
 
Share this answer
 
Comments
Nethaji chennai 18-Aug-16 3:20am    
thank you karthik .
Karthik_Mahalingam 18-Aug-16 3:22am    
welcome

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