I have checkbox and textbox control from asp.net on the contentplaceholder. I want to call the javascript function for enabling the textbox control depending on the checked status of the checkbox. I have written following javascript for this-
name of the checkbox & textbox
respectively after rendering it to browser ctl00$ContentPlaceHolder1$chkCall, ctl00$ContentPlaceHolder1$txtCall
function chkChanged() {
try {
var echk = document.getElementsByName('ctl00$ContentPlaceHolder1$chkCall');
var etxt = document.getElementsByName('ctl00$ContentPlaceHolder1$txtCall');
if (echk.Checked) {
etxt.Enabled = true;
}
else {
etxt.Enabled = false;
etxt.Text = "";
}
return true;
}
catch (err) {
alert(err.Message);
return false;
}
}
When i'm executing above script then it calls function but the code is not working for the control. And it is not throwing any exception.
What is wrong in above script?
thanks.
Use this script instead:
var echk = document.getElementById("<%= chkCall.ClientID %>");
var etxt = document.getElementById("<%= txtCall.ClientID %>");