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

Not "All"

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
I know I saw the answer to this somewhere but now I can't find it. How do I make an "All" checkbox deselect when one or more other checkboxes are selected? Thanks!

Don
 
Dear Don,

This runs in IE5 on NT4, Win95 and Win2000. It may not have the exact behavior you desire so you will have to make some changes.

Good luck
-pete

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
function checkBoxChange(){

var oEle = window.event.srcElement;
if ( 0 != oEle.name.indexOf(&quot;All&quot;) && oEle.checked){
document.form1.All.checked = false;
}
}
-->
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME=&quot;form1&quot;>
All: <input name=&quot;All&quot; type=&quot;checkbox&quot; value=&quot;0&quot; onclick=&quot;checkBoxChange()&quot;><br>
Red: <input name=&quot;Red&quot; type=&quot;checkbox&quot; value=&quot;1&quot; onclick=&quot;checkBoxChange()&quot;><br>
Green: <input name=&quot;Green&quot; type=&quot;checkbox&quot; value=&quot;0&quot; onclick=&quot;checkBoxChange()&quot;><br>
Blue: <input name=&quot;Blue&quot; type=&quot;checkbox&quot; value=&quot;3&quot; onclick=&quot;checkBoxChange()&quot;><br>
</FORM>
 
Pete,

Thanks! Though I'm not a programmer at all, I got it to work just fine once I realized that &quot;ALL&quot; was case sensitive. My &quot;value&quot; was already in use with the necessary field value but I can code that into the search script just as easily, I think (I hope). Coincidentally, your example has the exact number of checkboxes I am using!

Unfortunately, it does not seem to work on Netscape 4.74. Maybe it's because this form, while being 99% HTML, is embedded into a VBscript - a detail that I forgot about when I made my original post. That was necessary since ultimately it will need to receive an outside value when loading to pass along to the next form.

One thing though: In IE, &quot;All&quot; deselects when choosing any of the others as it should, but choosing &quot;All&quot; once again does not deselect the others. Do you know how I can fix that and get it to work on Netscape?

Thanks again!

Don
 
Don,

This works as you asked in IE5(NT4/Win95,98,2000) and Netscape 4.72(Win95/NT4)

Hope this helps
-pete

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
function checkBoxChange( oThis){

// if All is not clicked and checked
if ( 0 != oThis.name.indexOf(&quot;All&quot;) && oThis.checked){

document.form1.All.checked = false;

// else if it is 'All' and it is checked
}else if ( 0 == oThis.name.indexOf(&quot;All&quot;) && oThis.checked){

document.form1.Red.checked = false;
document.form1.Green.checked = false;
document.form1.Blue.checked = false;
}
}
-->
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME=&quot;form1&quot;>
All: <input name=&quot;All&quot; type=&quot;checkbox&quot; value=&quot;0&quot; onclick=&quot;checkBoxChange(this)&quot;><br>
Red: <input name=&quot;Red&quot; type=&quot;checkbox&quot; value=&quot;1&quot; onclick=&quot;checkBoxChange(this)&quot;><br>
Green: <input name=&quot;Green&quot; type=&quot;checkbox&quot; value=&quot;0&quot; onclick=&quot;checkBoxChange(this)&quot;><br>
Blue: <input name=&quot;Blue&quot; type=&quot;checkbox&quot; value=&quot;3&quot; onclick=&quot;checkBoxChange(this)&quot;><br>
</FORM>
 
Pete,

It works like a charm! It's perfect and thanks so much! I certainly couldn't have done it without your help. I was able to write a simple If Else statement based on which checkboxes are checked in my search script that recreates the needed form values to perform the actual search.

Don
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top