NYCPHP Meetup

NYPHP.org

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

Phillip Powell phillip.powell at adnet-sys.com
Tue Apr 13 18:30:39 EDT 2004


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
>





More information about the talk mailing list