Discuss object.length undefined in the JavaScript Development forum on Dev Shed. object.length undefined JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.
if only 1 checkbox is generated, and it is checked...the elemLength var is undefined....even though there is one .listing that is checked. I can do an alert (form1.listing.value) and it does show the $someID.
if 2+ checkboxes are generated, and 2+ of them are checked...elemLength show's it's length (ie how many are checked).
Posts: 1,559
Time spent in forums: 2 Days 14 h 10 m 18 sec
Reputation Power: 12
i think it's because the object hasn't been turned into an array unless there is more than one, so .length isn't of vaild usage...why can't you just test and see if it's undefined and if it is then you know it's one, like this:
Code:
var elemLength =document.form1.listing.length;
if (elemLength==undefined) {
elemLength=1;
}
Last edited by jacktasia : June 28th, 2004 at 08:07 PM.
Posts: 1,559
Time spent in forums: 2 Days 14 h 10 m 18 sec
Reputation Power: 12
well, you of course would have to do something like this...
Code:
if (elemLength==undefined) {
elemLength=1;
if (document.form1.listing.checked) {
// we know the one and only is checked
}
} else {
for (var i = 0; i<elemLength; i++) {
if (form1.listing[i].checked) {
//do some work here.
}
}
}