🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.javascript
Article #39781

Pogrupowane checkboxy, zaznaczanie i maly problem

#39781
From: Wajrak
Date: Fri, 05 May 2006 12:56
228 lines
7420 bytes
Witam, nie moglem znalezc niczego podobnego na grupie wiec napisze cos
napisze.
Mam taki skrypcik:

<HEAD>

<SCRIPT LANGUAGE="JavaScript">

function checkAllA() {
for (var i = 1; i <= document.checkboxform.length; i++) {
box = eval("document.checkboxform.ins_" + i);
if (box.checked == false) box.checked = true;
   }
}

function uncheckAllA() {
for (var i = 1; i <= document.checkboxform.length; i++) {
box = eval("document.checkboxform.ins_" + i);
if (box.checked == true) box.checked = false;
   }
}

function switchAllA() {
for (var i = 1; i <= document.checkboxform.length; i++) {
box = eval("document.checkboxform.ins_" + i);
box.checked = !box.checked;
   }
}

function checkAllB() {
for (var i = 1; i <= document.checkboxform.length; i++) {
box = eval("document.checkboxform.B" + i);
if (box.checked == false) box.checked = true;
   }
}

function uncheckAllB() {
for (var i = 1; i <= document.checkboxform.length; i++) {
box = eval("document.checkboxform.B" + i);
if (box.checked == true) box.checked = false;
   }
}

function switchAllB() {
for (var i = 1; i <= document.checkboxform.length; i++) {
box = eval("document.checkboxform.B" + i);
box.checked = !box.checked;
   }
}

function checkAllC() {
for (var i = 1; i <= document.checkboxform.length; i++) {
box = eval("document.checkboxform.C" + i);
if (box.checked == false) box.checked = true;
   }
}

function uncheckAllC() {
for (var i = 1; i <= document.checkboxform.length; i++) {
box = eval("document.checkboxform.C" + i);
if (box.checked == true) box.checked = false;
   }
}

function switchAllC() {
for (var i = 1; i <= document.checkboxform.length; i++) {
box = eval("document.checkboxform.C" + i);
box.checked = !box.checked;
   }
}

function test() {
	for ( i=0 ; i <= document.checkboxform.length ; i++ )
document.write     (document.getElementById['ins_'].value);

}
</script>
</HEAD>

I takiego forma z checkboxami:

<BODY>

<center>
<form name=checkboxform>
<table width="662" border="0">
  <tr>
    <td><div align="center">
      <input name="button" type=button onClick="checkAllA()"
value="Zaznacz A">
      <br>
      <input name="button" type=button onClick="uncheckAllA()"
value="Odznacz A">
      <br>
      <input name="button" type=button onClick="switchAllA()"
value="Odwroc A">
    </div></td>
    <td><div align="center">
      <input name="button2" type=button onClick="checkAllB()"
value="Zaznacz B">
      <br>
      <input name="button2" type=button onClick="uncheckAllB()"
value="Odznacz B">
      <br>
      <input name="button2" type=button onClick="switchAllB()"
value="Odwroc B">
    </div></td>
    <td><div align="center">
      <input name="button3" type=button onClick="checkAllC()"
value="Zaznacz C">
      <br>
      <input name="button3" type=button onClick="uncheckAllC()"
value="Odznacz C">
      <br>
      <input name="button3" type=button onClick="switchAllC()"
value="Odwroc C">
    </div></td>
  </tr>
  <tr>
    <td width="273"><div align="center">
      <input name=ins_1 type=checkbox id="ins_1" checked>
      <br>
      <input type=checkbox name=ins_2 checked>
      <br>
      <input type=checkbox name=ins_3 checked>
      <br>
      <input type=checkbox name=ins_4 checked>
      <br>
      <input type=checkbox name=ins_5 checked>
      <br>
      <input type=checkbox name=ins_6 checked>
      <br>
      <input type=checkbox name=ins_7 checked>
      <br>
      <input type=checkbox name=ins_8 checked>
      <br>
      <input type=checkbox name=ins_9 checked>
      <br>
      <input type=checkbox name=ins_10 checked>
      <br>
      <input type=checkbox name=ins_11 checked>
      <br>
      <input type=checkbox name=ins_12 checked>
      <br>
      <input type=checkbox name=ins_13 checked>
      <br>
      <input type=checkbox name=ins_14 checked>
      <br>
      <input name=ins_15 type=checkbox id="ins_15" checked>
    <br>
        <input name=ins_34 type=checkbox id="ins_34" checked>
    </div></td>
    <td width="273"><div align="center">
      <input name=upd_1 type=checkbox id="B1" checked>
      <br>
      <input type=checkbox name=B2 checked>
      <br>
      <input type=checkbox name=B3>
      <br>
      <input type=checkbox name=B4 checked>
      <br>
      <input type=checkbox name=B5 checked>
      <br>
      <input type=checkbox name=B6 checked>
      <br>
      <input type=checkbox name=B7 checked>
      <br>
      <input type=checkbox name=B8 checked>
      <br>
      <input type=checkbox name=B9 checked>
      <br>
      <input type=checkbox name=B10 checked>
      <br>
      <input type=checkbox name=B11 checked>
      <br>
      <input type=checkbox name=B12 checked>
      <br>
      <input type=checkbox name=B13 checked>
      <br>
      <input type=checkbox name=B14 checked>
    </div></td>
    <td width="273"><div align="center">
      <input name=del_1 type=checkbox id="C1" checked>
      <br>
      <input type=checkbox name=C2 checked>
      <br>
      <input type=checkbox name=C3 checked>
      <br>
      <input type=checkbox name=C4 checked>
      <br>
      <input type=checkbox name=C5 checked>
      <br>
      <input type=checkbox name=C6 checked>
      <br>
      <input type=checkbox name=C7 checked>
      <br>
      <input type=checkbox name=C8 checked>
      <br>
      <input type=checkbox name=C9 checked>
      <br>
      <input type=checkbox name=C10 checked>
      <br>
      <input type=checkbox name=C11 checked>
      <br>
      <input type=checkbox name=C12 checked>
      <br>
      <input type=checkbox name=C13 checked>
      <br>
      <input type=checkbox name=C14 checked>
    </div></td>
  </tr>
</table>
<br>
<br>
<input name="button4" type=button onClick="test()" value="Zaznacz A">
</form>
</center>

Wszystko dziala pieknie dopoki mam checkboxy nazywane kolejno upd_1m
upd_2, upd_3. Problem powstaje w momeci kiedy checkboxy maja
nieposortowane nazwy lub sa w nich przeskoki np. upd_1, upd_2, upd_34,
upd_3 i js zaznacza tlyko checkboxy do upd_2 pozniej olewa reszte.

Bede wdzieczny za wszelkie sugestje jak sie z tym uporac bo juz powoli
zaczynam sobie wlosy z glowy wyrywac a z js mam stycznosc od wczoraj:)

Pozdrawiam
Wajrak
Technical Details
Message-ID: <1146833784.940035.294940@j33g2000cwa.googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.glorb.com!postnews.google.com!j33g2000cwa.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.glorb.com!postnews.google.com!j33g2000cwa.googlegroups.com!not-for-mail
From: "Wajrak" <wajrak@gmail.com>
Newsgroups: pl.comp.lang.javascript
Subject: Pogrupowane checkboxy, zaznaczanie i maly problem
Date: 5 May 2006 05:56:24 -0700
Organization: http://groups.google.com
Lines: 229
Message-ID: <1146833784.940035.294940@j33g2000cwa.googlegroups.com>
NNTP-Posting-Host: 83.18.39.138
Mime-Version: 1.0
X-Trace: posting.google.com 1146833795 2750 127.0.0.1 (5 May 2006 12:56:35 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 5 May 2006 12:56:35 +0000 (UTC)
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: j33g2000cwa.googlegroups.com; posting-host=83.18.39.138;   posting-account=3mI6-A0AAABRanzNhQWXiws8Mpsa9Vmd
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit