[Javascript] Auto deleselecting a check box

Paul Novitski paul at novitskisoftware.com
Thu Apr 29 13:57:17 CDT 2004


Flavio & Peter,

I'd quibble with your solution, Flavio, only because you've hard-coded the 
number of checkboxes; if (when!) countries are added or removed someone 
would have to remember to revise the script.

Likewise, Peter, your solution assumes that the Tell You Later checkbox 
comes last.  If someone moves it to the top of the list, your code has to 
be changed.

I'm not saying a script shouldn't be dedicated to a specific html 
structure!  It's just that I see html content change so much that I try to 
save myself a lot of work by making my scripts a bit light on their feet 
and more forgiving of page format & content changes...

Also, Peter, your code assumes that the onClick event occurs when a country 
box is checked, whereas it will also fire if one is unchecked, so you 
really need to include the value of the checked property in your logic.

Paul


At 11:12 AM 4/29/2004, Flavio Gomes wrote:
><script>
>function UnCheckTellYouLater(oForm)
>{
>   countriesbeen = oForm.countriesbeen;
>   countriesbeen[3].checked = !(countriesbeen[0].checked ||
>countriesbeen[1].checked || countriesbeen[2].checked);
>}
></script>


At 11:14 AM 4/29/2004, Peter Brunone wrote:
>Well, you probably don't want to call it in the last checkbox, but here's 
>the basic idea:
>
>function UnCheckTellYouLater() {
>     var i = myForm.countriesbeen.length - 1;
>     myForm.countriesbeen[i].checked = false;
>     }





More information about the Javascript mailing list