[Javascript] struts form using javascript code

Hassan Schroeder hassan at webtuitive.com
Wed Mar 3 10:28:36 CST 2004


Chris Tifer wrote:

> I'm pretty sure I've already solved it. There's only one "list" element 
> and he's trying to check the length on it.

That's OK, a length of 1 is legal :-)

> He can either add more of them and check the length ( a collection ) or 
> access that field's value and check the length on that.

Actually, first he's declaring the Array incorrectly:

   menus = new Array; /* right: menus = new Array(); */

   var checkBoxes = driversDisplayForm.elements["list"];

/* :: and then, here in this loop, "menus" is being treated as
    a string, not an array; declared as a string, this works...
  */

   for(var i = 0; i < checkBoxes.length; i++)
   {
   if(checkBoxes[i].checked)
     {
       menus = menus+","+i; // string concatenation in progress :-)
       value = true;
     }
   }

/* Just generically speaking, using 'value'*, an attribute of many
    objects, as a variable name seems like an insanely bad idea to
    me -- even if it's not on the list of reserved words...

    *earlier declared as: var value = false;
  */

YMMV!
-- 
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                           dream.  code.





More information about the Javascript mailing list