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

Need Help with Checkbox Toggle--Stumped 1

Status
Not open for further replies.

dougcranston

Technical User
Oct 5, 2001
326
US
I am trying to create a function that can be called from a form to ensure only appropriate checkboxes are selected.

I can create "hard coded" code for each grouping but with at present 30 groupings with the potential of more, that is neither smart nor prudent.

I have checked the books I have, searched this site, and the web and nothing has seemed to answer my problem.

Although I am sure DOM is the appropriate approach, I am stumped on how to proceed. I have been remiss in becoming more proficient with utilizing the DOM but I am no where close to what I need, and as with many of the posts here, I have an imposed deadline..

So any suggestions, or possibly a site with a snippet that might shed light on this would be greatly appreciated.

I have placed a small portion of the code, and some pseudo code on what I think needs to happen, but I am open to suggestions. My thought would be to trigger the function calls using the onClick event.. Atleast that was how I envisioned doing it.

Thanks alot in advance.

Doug Cranston..

----- code follows ------


<head>

<script language="JavaScript"><!--

function checkSkillShare(skl,shr,trn) {

Pseudo code..

If skl is checked and/or shr is checked
then uncheck trn

}

function checkTrain(skl,shr,trn) {

Pseudo code..

If trn is checked
then uncheck skl AND shr

}

//--></script>

</head>

<body>

<form name="myForm">
<!-- this is a start if a chkbox grouping -->
<input type="checkBox" id="PCskl" name="PCskl" onClick="checkSkillShare(PCskl,PCshr,PCtrn)">PC Skilled
<input type="checkBox" id="PCshr" name="PCshr" onClick="checkSkillShare(PCskl,PCshr,PCtrn)">PC Willing to Share
<input type="checkBox" id="PCtrn" name="PCtrn" onClick="checkTrain(PCskl,PCshr,PCtrn)">PC Needs Training<br>
<!-- this is then end of a grouping -->
<!-- this is a start if a chkbox grouping -->
<input type="checkBox" id="Accessskl" name="Accessskl" onClick="checkSkillShare(Accessskl,Accessshr,Accesstrn)">Access Skilled
<input type="checkBox" id="Accessshr" name="Accessshr" onClick="checkSkillShare(Accessskl,Accessshr,Accesstrn)">Access Willing to Share
<input type="checkBox" id="Accesstrn" name="Accesstrn" onClick="checkTrain(Accessskl,Accessshr,Accesstrn)">Access Needs Training<br>
<!-- this is then end of a grouping -->


</form>

</body>
 
Where you are calling the functions, you should put the values in strings... so change this:

Code:
checkSkillShare(PCskl,PCshr,PCtrn)

to this:

Code:
checkSkillShare('PCskl', 'PCshr', 'PCtrn');

And then in the functions, you can use:

Code:
skl = document.getElementById(skl);
shr = document.getElementById(shr);
trn = document.getElementById(trn);
if (skl.checked || shr.checked) trn.checked = false;

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Dan,

A thousand pardon's.

Yes it did..

Have been out of pocket, between work, and more importantly family health problem, have not been on line .

It solved the problem.. Stars to you.. And shame on me..

I got your posting.. And after testing it I thought I had responded, but clearly I did not.

Again thanks for the great posting and quick response.

Dougc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top