Re: Javascript array [] length is undefined when only single element

From: Date: Wed, 18 Feb 2004 01:53:32 +0000
Subject: Re: Javascript array [] length is undefined when only single element
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-178046@lists.php.net to get a copy of this message
On Tue, 2004-02-17 at 20:21, Daevid Vincent wrote: > Okay kids. Here's another strange one. Very simple form. The array is > dynamically generated from PHP as per the suggested method: > http://us2.php.net/manual/en/faq.html.php#faq.html.arrays > > However, when there is only a single element, the myMultiSelect.length is > undefined in javascript. > If there are two or more elements, then the length works as expected... This is a javascript question not a PHP question, but how about: selectedAudits = 0; if (myMultiSelect.length) { for(i = 0; i < myMultiSelect.length; i++) if (myMultiSelect[i].checked) selectedAudits++; } else { if (myMultiSelect.checked) selectedAudits++; } -- Adam Bregenzer adam@bregenzer.net http://adam.bregenzer.net/

« previous php.general (#178046) next »