Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validating multiple checkboxes

Status
Not open for further replies.

song2siren

Programmer
Jun 4, 2003
103
GB
I have a form on an asp page which generates up to six checkboxes named speaker1Del, speaker2Del etc depending on whether my SQL database contains certain information.

However, I need to validate these checkboxes so that for however many checkboxes (up to six) are created, if all of them are checked by the user, I need an alert box to pop up requiring the user to uncheck at least one.

I'm sure this is fairly simple. Any help would be much appreciated.
 
u have to construct the Js using ASP, lets say i am going to randomly output 6 checkboxes, my ASP code will be:
<%
for i=0 to 10
response.write &quot;<input type='checkbox' name='Gen&quot;&i&&quot;'>Gen&quot;&i&&quot;<br>&quot;
next
%>

now to build the JS
<form name=&quot;FormName&quot;>
<%
js=&quot;&quot;
for i=0 to 10
js=js&&quot; document.FormName.Gen&quot;&i&&quot;.checked==true && &quot;
response.write &quot;<input type='checkbox' name='Gen&quot;&i&&quot;'>Gen&quot;&i&&quot;<br>&quot;
next
js=mid(js,1,len(js)-3)
%>
<input type=&quot;button&quot; onclick=&quot;CheckAll()&quot; value=&quot;Check&quot;>
<script>
function CheckAll()
{
if(<%=js%>)
{
alert(&quot;All Checked&quot;)
}
}
</script>
</form>


try it...

Known is handfull, Unknown is worldfull
 
Hi vbkris

I'm getting in a bit of a mess with this. There's always at least one checkbox, so speaker1Del is coded outside the ASP tag, but for speaker2Del to speaker6Del, each block of ASP looks as follows:

<%
If speakerListID(2) <> &quot;&quot; then
speakerID = speakerListID(2)

SQLStmt = &quot;SELECT * &quot;
FROMStmt = &quot;FROM JPL_conf_speakers &quot;
WHEREStmt = &quot;WHERE speakerID = '&quot; & speakerID & &quot;'&quot;
SQLStmt = SQLStmt & FROMStmt & WHEREStmt

Set RS = Connection.Execute(SQLStmt)
Set SQLStmt = Nothing
Set FROMStmt = Nothing
Set ORDERStmt = Nothing

speakerTitle = RS.Fields(&quot;speakerTitle&quot;)
speakerFName = RS.Fields(&quot;speakerFName&quot;)
speakerSName = RS.Fields(&quot;speakerSName&quot;)
speakerTitleEnd = RS.Fields(&quot;speakerTitleEnd&quot;)
Response.write(vbCrlf & vbTab & _
&quot;<input type='hidden' name='speakerID' value='&quot; & speakerID & &quot;'>&quot;)
if speakerID = speakerListID(2) then _
if speakerTitle <> &quot;&quot; then response.write(speakerTitle & &quot; &quot;) end if
Response.write(speakerFName & &quot; &quot; & speakerSName)
if speakerTitleEnd <> &quot;&quot; then response.write(&quot; &quot; & speakerTitleEnd) end if
Set speakerID = nothing
Set speakerTitle = nothing
Set speakerFName = nothing
Set speakerSName = nothing
Set speakerTitleEnd = nothing
response.write(&quot;</td>&quot; & vbCrlf & vbTab & _
&quot;<td width='10%'></td>&quot; & vbCrlf & vbTab & _
&quot;<td width='20%'><div align='right'>&quot; & vbCrlf & vbTab & _
&quot;<input name='speaker2Del' type='checkbox' class='TextSmall'>&quot; & vbCrlf & vbTab & _
&quot;<span class='TextSmall'>Delete</span></div></td>&quot; & vbCrlf & vbTab & _
&quot;</tr>&quot; & vbCrlf & vbTab & _
&quot;</table>&quot; & vbCrlf & vbTab & _
&quot;</td>&quot; & vbCrlf & vbTab & _
&quot;</tr>&quot;)
end if %>

Thanks again
 
does my method work?
if it does then why not incroporate it in ur code?

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top