AW: AW: [Javascript] checkboxes in array
Michael Borchers
borchers at tridem.de
Mon Apr 4 02:50:55 CDT 2005
> 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[]
something like this?
<input type="checkbox" name="typ[]" value="S06-001" style="border:none; ">
<input type="text" name="stck[]" style="width:50px; " value="0" onFocus="this.value='';document.getElementsByName('typ[]').checked=true">
I need to have it without certain IDs or names, just arrays []
More information about the Javascript
mailing list