AW: AW: [Javascript] checkboxes in array

Michael Borchers borchers at tridem.de
Tue Mar 15 08:49:35 CST 2005


> Von: Mike Dougherty [mailto:mdougherty at pbp.com]
> Gesendet: Dienstag, 15. März 2005 15:38
> An: [JavaScript List]
> Betreff: Re: AW: [Javascript] checkboxes in array
> 
> 
> How about this:?
> 
> <label for='typ_1'>typ 1:</label>
> <input type='checkbox' name='typ[]' id='typ_1' value='1' />
> <label for='stck_1'>stck 1:</label>
> <input type='text' name='stck[]' id='stck_1' value='4' 
> onFocus="checkIt('typ_1');" />
> 
> <label for='typ_2'>typ 2:</label>
> <input type='checkbox' name='typ[]' id='typ_2' value='2' />
> <label for='stck_2'>stck 2:</label>
> <input type='text' name='stck[]' id='stck_2' value='0' 
> onFocus="checkIt('typ_2');" />
> 
> [etc.]
> 
> <script type='text/javscript'>
> function checkIt( tcCBId ) {
>    var loCB = document.getElementById( tcCBId );
>    if (loCB) {
>      loCB.checked = true ;
>      }
> }
> </script>
> 
> 
> Note: the use of the <label> tag aids accessibility on the 
> checkbox because you can click the 
> label to toggle the checkbox value (rather than the little 
> square of the checkbox itself)  the 
> <label> tag also provides a convenient hook for styling - it 
> would be even better if IE understood 
> attribute selectors so your CSS could be label[for=typ_1] 
> {rule} but whatever..  

nice <label> tip there, thanks
can I also do it without giving a certain id?
f.e. not typ_2 or typ_3 but yet another array or similar? typ_id[]



More information about the Javascript mailing list