469,590 Members | 2,464 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,590 developers. It's quick & easy.

Custom Validator for a checkboxlist control Strange behavior.

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="JavaScript">

function ChkMusicTasteSelection(source, arguments) {

var t = 0;

for(var i = 0; i < 31; i++) {

var chkbx = document.all.item("musicTaste_" + i);

// document.write(chkbx) --> null (getElementById() produces the
same effect)

if(chkbx.checked == true){
t++;
}
}

if((t <= 5) && (t >= 1)) {

arguments.IsValid = true;
}
else {
arguments.IsValid = false
}
}
}

</script>

</HEAD>
<body>
<form id="Form1" method="post" runat="server">

...
<TD style="HEIGHT: 188px"><asp:checkboxlist 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:640px;">
<tr>
<td><input id="musicTaste_0" type="checkbox" name="musicTaste:0"
/><label for="musicTaste_0">60's</label></td>
<td><input id="musicTaste_1" type="checkbox" name="musicTaste:1"
/><label for="musicTaste_1">70's</label></td>
<td><input id="musicTaste_2" type="checkbox" name="musicTaste:2"
/><label for="musicTaste_2">80's</label></td>

...
Jul 23 '05 #1
1 3082
On 18 Jul 2004 07:32:33 -0700, Itai wrote:
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.
I did not experience the same problem when I
failed to visit the URL you did not supply.

I cannot see what you are on about.
Anyone know what to do?


Give URL. ;-)

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Alex Shirley | last post: by
3 posts views Thread by tshad | last post: by
3 posts views Thread by cannontrodder | last post: by
reply views Thread by Piotr Strycharz | last post: by
4 posts views Thread by Rick | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.