Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-13-2004, 12:09 AM   PM User | #1
schmazz
New to the CF scene

 
Join Date: Nov 2004
Location: Oregon
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
schmazz is an unknown quantity at this point
error: "has no properties" in function

Hello,
I am working on a loop that counts my elements. When I debug, I get the error "e.elements[i] has no properties" (line 10).

I have defined i as a variable with value of 0, and a form passes to e. So, I have both i and e defined as something... What's my problem? I don't understand how neither of them has properties. (Or which one, for that matter, doesn't have properties).

PHP Code:
function countElements(e){
var 
rb=0
var b=0
var tb=0
var cb=0
var i=0
var totalNum=e.elements.length

for(i=0;i<=totalNum;i++){
    if (
e.elements[i].type=="text")tb=tb+1;
    else if (
e.elements[i].type=="button")b=b+1;
    else if (
e.elements[i].type=="radio")rb=rb+1;
    else if (
e.elements[i].type=="checkbox")cb=cb+1

Thanks again,
Kristina
schmazz is offline   Reply With Quote
Old 11-13-2004, 12:23 AM   PM User | #2
codegoboom
Regular Coder

 
Join Date: Aug 2004
Location: codegoboom@yahoo.com
Posts: 999
Thanks: 0
Thanked 0 Times in 0 Posts
codegoboom is an unknown quantity at this point
when i = length, the error will occur, because the collection is zero-based, so change "i<=totalNum" to "i<totalNum"
__________________
*this message will self destruct in n-seconds*
codegoboom is offline   Reply With Quote
Old 11-13-2004, 07:46 AM   PM User | #3
schmazz
New to the CF scene

 
Join Date: Nov 2004
Location: Oregon
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
schmazz is an unknown quantity at this point
Whoa, that was all? Thanks codegoboom!
schmazz is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:33 PM.


Advertisement
Log in to turn off these ads.