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

CheckBox Function 1

Status
Not open for further replies.

ezmaRell

Programmer
Aug 7, 2002
3
US
I am working on a page that has 4 different arrays of checkboxes - I would like to create a function that will
loop thru the array of chkboxes to determine which one the user selected and return the name of the chkbox and the number.

The first part of my code is below - please assist -I am a new programmer and this is my first assignment.

function BoxChecked(chkBox){
var aName;
var sName;
var i;
var aEval;
var obj;

aName=chkBox.name.split("_");
sName=aName[0];

if (aName[0]=="chkCircType"){
//If the "All" box is checked and the user clicked a box other than "All"
//"chkCircType_1" represents the "all" checkbox

if((ccform.item("chkCircType_1").checked) && (chkBox.name != "chkCircType_1"))
{//then turn off the "All" box and...
ccform.item("chkCircType_1").checked=false;
// turn off all boxes except the box the user checked.
for(i=0; i<ccform.hCircTypeCount.value; i++)
{
if ((i+1) != aName[1]){
ccform.item(&quot;chkCircType_&quot;+(i+1)).checked=false;}
else {
ccform.item(&quot;chkCircType_&quot;+(i+1)).checked=true;}
}}
else {
if(ccform.item(&quot;chkCircType_1&quot;).checked) {
for(i=0; i<ccform.hCircTypeCount.value; i++){
ccform.item(&quot;chkCircType_&quot;+(i+1)).checked=true; }
}}}

Thanks for your help.

 
hi ezmaRell,

here's a quick example that should help you get started:
[tt]
<html>
<head>
<title>checkbox array</title>

<script name=&quot;javascript&quot;>
function getValues() {
var sValues = &quot;&quot;;
var args = arguments;

// loop through array of arguments
for (a = 0; a < args.length; a++) {
// loop through elements of each argument
for (e = 0; e < args[a].length; e++) {
if (args[a][e].checked)
sValues += args[a][e].name +
&quot; = &quot; + args[a][e].value + &quot;\n&quot;;
}
}
alert(sValues);
}

</script>

<style type=&quot;text/css&quot;>
</style>

<meta name=&quot;author&quot; content=&quot;?&quot;>
<meta name=&quot;keywords&quot; content=&quot;?&quot;>
<meta name=&quot;description&quot; content=&quot;?&quot;>
</head>

<body onload=&quot;&quot;>
<form name=&quot;&quot; action=&quot;&quot; method=&quot;&quot;>
group one:
<input type=&quot;checkbox&quot; name=&quot;box1&quot; value=&quot;a&quot; />
<input type=&quot;checkbox&quot; name=&quot;box1&quot; value=&quot;b&quot; />
<input type=&quot;checkbox&quot; name=&quot;box1&quot; value=&quot;c&quot; />
<input type=&quot;checkbox&quot; name=&quot;box1&quot; value=&quot;d&quot; />
<p />
group two:
<input type=&quot;checkbox&quot; name=&quot;box2&quot; value=&quot;one&quot; />
<input type=&quot;checkbox&quot; name=&quot;box2&quot; value=&quot;two&quot; />
<input type=&quot;checkbox&quot; name=&quot;box2&quot; value=&quot;three&quot; />
<input type=&quot;checkbox&quot; name=&quot;box2&quot; value=&quot;four&quot; />
<p />
<input type=&quot;button&quot; name=&quot;&quot; value=&quot;getValues();&quot; onclick=&quot;getValues(this.form.box1,this.form.box2);&quot; />
</form>
</body>
</html>
[tt] =========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top