NYCPHP Meetup

NYPHP.org

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

Phillip Powell phillip.powell at adnet-sys.com
Tue Apr 13 15:31:48 EDT 2004


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&nbsp;&nbsp;
<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




More information about the talk mailing list