I've used this code before (it works on all checkboxes, regardless of name):
<SCRIPT LANGUAGE="_javascript_">
<!-- Begin
function checkAll() {
var el = document.forms[0].elements;
for(var i = 0 ; i < el.length ; ++i) {
  if(el[i].type == "checkbox") {
   el[i].checked = true;
}
}
return true;
}
//  End -->
</script>

<!---in the form--->
<input type="button" value="Check All" >
----- Original Message -----
From: "Tim Laureska" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Thursday, October 23, 2003 8:36 AM
Subject: JS help - select all checkboxes

> This is probably old hat for most, but it's a first for me....
>
> I have a page of records laid out in a table that results from a query
> ... I want the option to delete all records or individual ones.
> Therefore, I have checkboxes next to each record.. deleting individual
> records was not a problem... but when I tried to use/modify a piece of
> js (script found on the net) to do a select all scenario, it throws a JS
> error ... I think because the records are dynamically generated.... I've
> seen some obscure references on how to do this "select all" scenario
> with multiple, dynamically generated records, but nothing I can put
> together to make it work.
>
> Can someone point me in the right direction here... the code I'm using
> off the net, which works fine in a static situation, is below , but of
> course there's only one <input type> line in my template
>
> <form name=f1>
> <input type="checkbox" name="c1" value="1">c1-1<BR>
> <input type="checkbox" name="c1" value="2">c1-2<BR>
> <input type="checkbox" name="c1" value="3">c1-3<BR>
> <input type="checkbox" name="c1" value="4">c1-4<BR>
> <input type="checkbox" name="c1" value="5">c1-5<BR>
> <input type="checkbox" name="c2" value="1">c2-1<BR>
> <input type="checkbox" name="c2" value="2">c2-2<BR>
> <input type="checkbox" name="c2" value="3">c2-3<BR>
> <input type="checkbox" name="c2" value="4">c2-4<BR>
> <input type="checkbox" name="c2" value="5">c2-5<BR>
>
>
> <input type="checkbox" name="c3" value="false"
> Not Checked<BR>
> <input type="checkbox" name="c4" value="true"
> Checked<BR>
> </form>
> <script>
> function doIt(v)
> {
>  for(var i=0;i<document.f1.c1.length;i++)
>    document.f1.c1[i].checked=eval(v);
>  for(var i=0;i<document.f1.c2.length;i++)
>    document.f1.c2[i].checked=eval(v);
>  document.f1.c3.checked=false;
>  document.f1.c4.checked=false;
> }
> </script>
>
> Tim
>
>
>
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to