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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check box validation

Status
Not open for further replies.

parames

MIS
Jun 26, 2000
71
MY
hi list..

i want to do validation for checkbox, where the user must select atleast one checkbox.. my asp code looks like this

------
<form action=&quot;admin_chancepack.asp&quot; name=&quot;form&quot; method=post onSubmit=&quot;return CheckPack(this)&quot;>
------
<%
Do while Not RS.EOF
iCount = iCount + 1 %>

<tr bgcolor=&quot;eeeeee&quot;>
<td><input type=CHECKBOX name=checkitem<%=iCount%> value&quot;<%=RS(&quot;pid&quot;)%>&quot;>
</tr>

<%
RS.Movenext
Loop
------
<input type=HIDDEN name=txtCount value=&quot;<%=iCount%>&quot;>
<p><input type=SUBMIT value=submit></p>
------

the problem is i don't know how to write the validation in javascript..

function CheckPack(form) {
{
for i=1; i<=document.form.txtCount.value; i++) {
??????????
}}

please help..

thanks a lot..
rgds,
parames.s
 
I assume you want to do the validation via client scripting since you are using JavaScript. Am I correct? If you are looking to using server side validation then you can use ASP(VbScrript). Let me know which you plan to use.
 
Dear Antzz, i want to use javascript validation.. Hope you can halp me..

thanks a lot..

rgds,
parames.s
 
Hi.

See the following code and you can find out, how to realize what you want.

<html>
<head>
<Script Language=&quot;JavaScript&quot;>
function checkB()
{
var elements=document.all[&quot;chk&quot;];
var num=document.all[&quot;chk&quot;].length;
for(i=0;i<num;i++)
{
if(elements.checked == true)
{
document.myForm.method=&quot;POST&quot;;
document.myForm.action=&quot;myASPPage.asp&quot;;
document.myForm.submit();
}
}

}

</Script>
</head>
<body>
<Form name=&quot;myForm&quot; id=&quot;myForm&quot;>
<input type=CHECKBOX name=&quot;chk&quot; id=&quot;chk1&quot; value=&quot;chk1&quot;>
<input type=CHECKBOX name=&quot;chk&quot; id=&quot;chk2&quot; value=&quot;chk2&quot;>
<input type=CHECKBOX name=&quot;chk&quot; id=&quot;chk3&quot; value=&quot;chk3&quot;>
<input type=CHECKBOX name=&quot;chk&quot; id=&quot;chk4&quot; value=&quot;chk4&quot;>
<input type=button value=&quot;Click Me&quot; onclick=&quot;checkB()&quot;>
</Form>
</body>
</html>

regards, Kirilla
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top