NYCPHP Meetup

NYPHP.org

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

Phillip Powell phillip.powell at adnet-sys.com
Tue Apr 13 16:04:27 EDT 2004


What about the other checkboxes, "select_all" and "deselect_all", along 
with other dynamically-generated checkbox groups that may also exist 
within this HTML resultset?

Phil

felix zaslavskiy wrote:

>Try this:
>for (var i = 0; i < document.imageForm.elements.length; i++){
>if(document.imageForm.elements[i].type == 'checkbox'){
>      document.imageForm.elements[i].checked = true;
>}
>}
>  
>
>>I am producing a form using PHP on the back end and Javascript on the
>>front end.  The resulting script will come to the browser as follows:
>>
>>[Code]
>><script>
>><!--
>>  function selectAll() {
>>   moveElement = eval("document.imageForm.move" + "[]");
>>   alert(moveElement);
>>   if (document.imageForm.select_all[0].checked) {
>>    for (i = 0; i < document.imageForm.move.length; i++) {
>>     document.imageForm.move[i].checked = true;
>>    }
>>  }
>> }
>>
>> function deSelectAll() {
>>  if (!document.imageForm.select_all[0].checked ||
>>document.imageForm.deselect_all[0].checked) {
>>   for (i = 0; i < document.imageForm.move.length; i++) {
>>    document.imageForm.move[i].checked = false;
>>   }
>>  }
>> }
>>//-->
>></script>
>>[/Code]
>>
>>This will work with a checkbox group that has to have this naming
>>convention for PHP:
>>
>>[Code]
>><input type=checkbox name=move[] value="myImage.gif"> - Move?
>>[/Code]
>>
>>I will also have a checkbox that will "select all" and "de-select all":
>>
>>[Code]
>><input type=checkbox name=select_all value=1 onChange="selectAll()"> -
>>Select All
>><input type=checkbox name=deselect_all value=1 onChange="deSelectAll()">
>>- De-select All
>>[/Code]
>>
>>I am not familiar at how Javascript can work with non-standard naming
>>conventions for event actions, can someone tell me what I'm doing
>>wrong?  This fails at least in Mozilla 1.6
>>
>>Thanx
>>Phil
>>
>>_______________________________________________
>>talk mailing list
>>talk at lists.nyphp.org
>>http://lists.nyphp.org/mailman/listinfo/talk
>>
>>    
>>
>
>
>  
>





More information about the talk mailing list