I have a bunch of checkboxes in my web form and what I'm trying to do is basically, count the number of checked in checkboxes and display it in the textbox below...
here is an example code for 2 of my checkboxes: and javascript function
<tr>
<td style="text-align:center;">
<asp:CheckBox ID="chk1" runat="server" ClientIDMode="Static" onclick="GetSCORE()" />
</td>
<td style="text-align:center;">
<asp:CheckBox ID="chk2" runat="server" ClientIDMode="Static" onclick="GetSCORE()" />
</td>
</tr>
JS:
function GetSCORE() {
try {
var ChkList = ["chk1", "chk2"];
var Score = 0;
var txtBHPSCageScore = document.getElementById("txtBHPSCageScore");
for (var i = 0; i < ChkList.length; i++) {
alert(chklist[i]);
var chkbox = document.getElementById(ChkList[i]);
if (chkbox.checked == true) {
Score = parseInt(Score) + 1;
}
}
//alert("here2");
if (txtScore != null) {
txtScore.value = Score;
}
}
catch (e) {
alert("Script Error : " + e.message);
}
}
So when the page loads, there no issues, but if i click into one of the checkboxes I get this error:
chklist not defined.
What might I be doing wrong?
EDIT:
I just used alert(chklist) to see what was going on, i commented it out and it says chkbox is null
Aucun commentaire:
Enregistrer un commentaire