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

Checkbox group validation 1

Status
Not open for further replies.

Mary01

Programmer
Jun 23, 2005
12
0
0
US
Hi,

I'm trying to validate a group of checkboxes(for as many records as my query returns). can somebody help me with that please?

Thank you
 
Possibly... perhaps if you explained the criteria you wished to validate them against.

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Webflo
 
Hi,

I want to make sure they are all checked.

Thank you!
 
Mary, perhaps if you showed some of your code or what you've attempted so far it would be easier to point you in the right direction. Here's an incredibly bare bones example:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

function validate() {
   var a = document.getElementsByTagName("input");
   for (i = 0; i < a.length; i++) {
      if (a[i].type == "checkbox") {
         if (!a[i].checked) {
            alert("one or more of the checkboxes are unchecked");
            return false;
         }
      }
   }
   alert("all the checkboxes are checked");
}

</script>
<style type="text/css"></style>
</head>
<body>

<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<br />
<input type="button" value="check 'em" onclick="validate()" />

</body>
</html>

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Thank you Kaht

I think what I was doing wrong was checking for the value of the checkbox and comparing it to null.

Thank you again,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top