Reputation: 303
I am using the below code to create a dynamic textbox and their onchange event.Event fired successfully and it doesn't return any value.Please help me to solve this.
txt_box.Attributes.Add("onchange", "loadValues('" + txt_box.ClientID + "')");
function loadValues(controlName) {
alert(controlName);
//control name comes here
var txtValue = document.getElementById(controlName);
//control also return null
if (txtValue.value.length > 0)
{
alert(txtValue.value.length);
}
}
Upvotes: 0
Views: 590
Reputation: 1527
try the following
txt_box.Attributes.Add("onchange", "loadValues(this)");
function loadValues(controlName) {
if($(controlName).attr('id').length > 0){
var id= $(controlName).attr('id');
var val= $('#'+id).val();
alert(val);
}
}
Upvotes: 0
Reputation: 1749
Was just about to answer the same as Ankush Jain, but then none jquery version:
function loadValues(control) {
alert(control.id);
//control name comes here
var txtValue = control.value;
//control also return null
if (txtValue.length > 0) {
alert(txtValue.length);
}
}
txt_box.Attributes.Add("onchange", "loadValues(this);");
Upvotes: 1