NYCPHP Meetup

NYPHP.org

[nycphp-talk] Javascript "select all" feature?

Beach Sun sol2ray at yahoo.fr
Wed Apr 14 00:12:01 EDT 2004


This select all thing has been going on for a little
while now.
Here is a more simple and elegant function.
<script>
   function CheckAll(x) {
  for (var i = 0; i <
document.forms[x].elements.length; i++) {
    if(document.forms[x].elements[i].type ==
'checkbox'   ){
      document.forms[x].elements[i].checked =
!(document.forms[x].elements[i].checked);
    }
  }
}
// the argument X is the name or the index number of
the form in the document.
</script>

This should work in all browsers.
By the way if you are using phpbtree my php btree
code.
I suggest you get the newer version. I keeps getting
better.
sol

______ PHPBTREE _______________
"when flat text is not smart enough and database
server is overkill..."
 http://www.phpbtree.com


--- Phillip Powell <phillip.powell at adnet-sys.com>
wrote:
> Works on my machine's browsers now, all of them, the
> right way, I hacked it:
> 
> <script>
> <!--
>   function selectAll(checkState, selectStatus, obj)
> {
>    if (document.imageForm.select_all.checked ||
> document.imageForm.deselect_all.checked) {
>     for (i = 0; i < obj.length; i++) {
>      obj[i].checked = checkState;
>     }
>    if (selectStatus.toLowerCase() == 'select')
> document.imageForm.deselect_all.checked = false;
>    if (selectStatus.toLowerCase() == 'deselect')
> document.imageForm.select_all.checked = false;
>   }
>  }
> //-->
> </script>
> 
>  <tr>
>   <td bgcolor=ffffff><a
> href="./images/mu-spin/kyrka.jpg">kyrka.jpg</a></td>
>   <td bgcolor=ffffff>Show Metadata</td>
>   <td bgcolor=ffffff><input type=checkbox
> name="move[]" value="kyrka.jpg"> - Move?</td>
> 
>  </tr>
>  <tr>
>   <td bgcolor=ffffcc><a
>
href="./images/mu-spin/banner.jpg.jpeg">banner.jpg.jpeg</a></td>
>   <td bgcolor=ffffcc><a
>
href=index.php?section=image&action=edit&chooseAlbum=1&album=mu-spin&id=147>Show
> Metadata</a></td>
>   <td bgcolor=ffffcc><input type=checkbox
> name="move[]" value="banner.jpg.jpeg"> - Move?</td>
>  </tr>
>  <tr>
> 
>   <td bgcolor=ffffff><a
>
href="./images/mu-spin/kyrka_gray.jpg">kyrka_gray.jpg</a></td>
>   <td bgcolor=ffffff><a
>
href=index.php?section=image&action=edit&chooseAlbum=1&album=mu-spin&id=145>Show
> Metadata</a></td>
>   <td bgcolor=ffffff><input type=checkbox
> name="move[]" value="kyrka_gray.jpg"> - Move?</td>
>  </tr>
>  <tr>
>   <td colspan=3 bgcolor=ddddee>
>    <input type=checkbox name="select_all" value=1
> onClick="selectAll(true, 'select',
> document.imageForm['move[]'])"> - Select
> All&nbsp;&nbsp;<input type=checkbox
> name="deselect_all" value=1
> onClick="selectAll(false, 'deselect',
> document.imageForm['move[]'])"> - De-Select All</td>
> 
> 
> Phil
> 
> Phillip Powell wrote:
> 
> > Well the good news is that it [sort of] works in
> all browsers.. bad 
> > news is that it [sort of] works in all browsers..
> sometimes it selects 
> > all, sometimes it does not...
> >
> > The only major change was that I changed
> "onChange" to "onClick"
> >
> > <script>
> > <!--
> >  function selectAll(checkState, obj) {
> >   if (document.imageForm.select_all.checked || 
> > document.imageForm.deselect_all.checked) {
> >    for (i = 0; i < obj.length; i++) {
> >     obj[i].checked = checkState;
> >    }
> >   if (document.imageForm.deselect_all.checked) 
> > document.imageForm.select_all.checked = false;
> >   if (document.imageForm.select_all.checked || 
> > !document.imageForm.deselect_all.checked) 
> > document.imageForm.deselect_all.checked = false;
> >  }
> > }
> > //-->
> > </script>
> >
> > <tr>
> >  <td bgcolor=ffffff><a 
> >
> href="./images/mu-spin/kyrka.jpg">kyrka.jpg</a></td>
> >  <td bgcolor=ffffff>Show Metadata</td>
> >  <td bgcolor=ffffff><input type=checkbox
> name="move[]" 
> > value="kyrka.jpg"> - Move?</td>
> >
> > </tr>
> > <tr>
> >  <td bgcolor=ffffcc><a 
> >
>
href="./images/mu-spin/banner.jpg.jpeg">banner.jpg.jpeg</a></td>
> >  <td bgcolor=ffffcc><a 
> >
>
href=index.php?section=image&action=edit&chooseAlbum=1&album=mu-spin&id=147>Show
> 
> > Metadata</a></td>
> >  <td bgcolor=ffffcc><input type=checkbox
> name="move[]" 
> > value="banner.jpg.jpeg"> - Move?</td>
> > </tr>
> > <tr>
> >
> >  <td bgcolor=ffffff><a 
> >
>
href="./images/mu-spin/kyrka_gray.jpg">kyrka_gray.jpg</a></td>
> >  <td bgcolor=ffffff><a 
> >
>
href=index.php?section=image&action=edit&chooseAlbum=1&album=mu-spin&id=145>Show
> 
> > Metadata</a></td>
> >  <td bgcolor=ffffff><input type=checkbox
> name="move[]" 
> > value="kyrka_gray.jpg"> - Move?</td>
> > </tr>
> > <tr>
> >  <td colspan=3 bgcolor=ddddee>
> >   <input type=checkbox name="select_all" value=1 
> > onClick="selectAll(true,
> document.imageForm['move[]'])"> - Select 
> > All&nbsp;&nbsp;<input type=checkbox
> name="deselect_all" value=1 
> > onClick="selectAll(false,
> document.imageForm['move[]'])"> - De-Select 
> > All</td>
> >
> > </tr>
> >
> >
> > Phil
> >
> >
> >
> > drydell at att.net wrote:
> >
> >> Wellington, give it a shot... it'll work in any
> browser, AFAIK
> >>
> >>
> >>  
> >>
> >>> Calm down, Phil, it'll be alright...
> >>>
> >>> I would try the code alone, nothing else on the
> page. Use
> >>> drydell at att.net's code (I haven't tested it but
> it looks great).
> >>>
> >>> Often a syntax error -- a missing brace, etc. --
> in javascript will
> >>> cause all kinds of silent havoc on yer code.
> Then paste back in,
> >>> function by function, testing after each one to
> make sure nothing
> >>> breaks.
> >>>
> >>> -- 
> >>> W
> >>>
> >>> _______________________________________________
> >>> talk mailing list
> >>> talk at lists.nyphp.org
> >>> http://lists.nyphp.org/mailman/listinfo/talk
> >>>   
> >>
> >> _______________________________________________
> >> talk mailing list
> >> talk at lists.nyphp.org
> >> http://lists.nyphp.org/mailman/listinfo/talk
> >>
> >>  
> >>
> >
> >
> > _______________________________________________
> > talk mailing list
> > talk at lists.nyphp.org
> > http://lists.nyphp.org/mailman/listinfo/talk
> >
> 
> 
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk


=====
Sol Touré
PHPBTREE
http://phpbtree.com


	
		
__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html



More information about the talk mailing list