[Javascript] Auto deleselecting a check box

Peter Brunone peter at brunone.com
Thu Apr 29 14:18:10 CDT 2004


>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.

   It was quick and dirty, to get the job done.  I'm sure we'd get another question if/when that failed to be sufficient :)

>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.

   All that is true, but he didn't ask for code to run through all the checkboxes and see if any but the "Tell You Later" are checked and if not to check the TYL box.  Since I'm often guilty of giving *too much* information, I try to tone it down until someone asks for more.

Cheers,

Peter

Original Message:
>From: Paul Novitski <paul at novitskisoftware.com>

>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