I am attempting to create an ASP.NET Custom Validator javascript for a
checkboxlist control. My goal is to limit the total number of
selections to be 1 - 5 at most. My problem is that I get a null
reference when I attempt to retrieve an object for an individual list
item, which of course results
in an "object required" error message.
Anyone know what to do? tnx in advance
-Itai.
Here is the code:
<HEAD>
....
<script language="JavaS cript">
function ChkMusicTasteSe lection(source, arguments) {
var t = 0;
for(var i = 0; i < 31; i++) {
var chkbx = document.all.it em("musicTaste_ " + i);
// document.write( chkbx) --> null (getElementById () produces the
same effect)
if(chkbx.checke d == true){
t++;
}
}
if((t <= 5) && (t >= 1)) {
arguments.IsVal id = true;
}
else {
arguments.IsVal id = false
}
}
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
...
<TD style="HEIGHT: 188px"><asp:che ckboxlist id="musicTaste "
runat="server"
Width="640px" RepeatColumns=" 5" RepeatDirection ="Horizontal ">
<asp:ListItem Value="1">60's</asp:ListItem>
<asp:ListItem Value="2">70's</asp:ListItem>
<asp:ListItem Value="3">80's</asp:ListItem>
...
Rendered Output: (browser ie6sp1)
<TD style="HEIGHT: 188px"><table id="musicTaste " border="0"
style="width:64 0px;">
<tr>
<td><input id="musicTaste_ 0" type="checkbox" name="musicTast e:0"
/><label for="musicTaste _0">60's</label></td>
<td><input id="musicTaste_ 1" type="checkbox" name="musicTast e:1"
/><label for="musicTaste _1">70's</label></td>
<td><input id="musicTaste_ 2" type="checkbox" name="musicTast e:2"
/><label for="musicTaste _2">80's</label></td>
...
checkboxlist control. My goal is to limit the total number of
selections to be 1 - 5 at most. My problem is that I get a null
reference when I attempt to retrieve an object for an individual list
item, which of course results
in an "object required" error message.
Anyone know what to do? tnx in advance
-Itai.
Here is the code:
<HEAD>
....
<script language="JavaS cript">
function ChkMusicTasteSe lection(source, arguments) {
var t = 0;
for(var i = 0; i < 31; i++) {
var chkbx = document.all.it em("musicTaste_ " + i);
// document.write( chkbx) --> null (getElementById () produces the
same effect)
if(chkbx.checke d == true){
t++;
}
}
if((t <= 5) && (t >= 1)) {
arguments.IsVal id = true;
}
else {
arguments.IsVal id = false
}
}
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
...
<TD style="HEIGHT: 188px"><asp:che ckboxlist id="musicTaste "
runat="server"
Width="640px" RepeatColumns=" 5" RepeatDirection ="Horizontal ">
<asp:ListItem Value="1">60's</asp:ListItem>
<asp:ListItem Value="2">70's</asp:ListItem>
<asp:ListItem Value="3">80's</asp:ListItem>
...
Rendered Output: (browser ie6sp1)
<TD style="HEIGHT: 188px"><table id="musicTaste " border="0"
style="width:64 0px;">
<tr>
<td><input id="musicTaste_ 0" type="checkbox" name="musicTast e:0"
/><label for="musicTaste _0">60's</label></td>
<td><input id="musicTaste_ 1" type="checkbox" name="musicTast e:1"
/><label for="musicTaste _1">70's</label></td>
<td><input id="musicTaste_ 2" type="checkbox" name="musicTast e:2"
/><label for="musicTaste _2">80's</label></td>
...
Comment