Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Size of javascript array?
Old 12-15-2010, 03:28 PM Size of javascript array?
Junior Talker

Posts: 1
Name: John Doe
Trades: 0
Hi, javascript newbie here.

While creating some checkboxes I've named all the checkboxes the same.

<input type="checkbox" name="check_list[]" value="1">
<input type="checkbox" name="check_list[]" value="2">
<input type="checkbox" name="check_list[]" value="3">
<input type="checkbox" name="check_list[]" value="4">

Normally, I'd be able to get the number of elements in the array with the following, if I hadn't included the brackets in the name:

document.MyForm.check_list.length;

However, when the name contains brackets, which I'm pretty certain is what is causing the problem, I'm not able to use my ordinary method.

Got any idea how to get the number of elements now?
Whateverz is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-15-2010, 03:39 PM Re: Size of javascript array?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
The idea that using [] in the field names will return an array in the HTTP request is incorrect and just makes the name attribute invalid.

By giving the checkboxes all the same name the checked items will be returned as a comma separated string
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-20-2010, 06:06 AM Re: Size of javascript array?
Banned

Posts: 3
Name: smithcruise23
Trades: 0
The length of any Java script array can be found by using its length property. Moreover, there has been the length property that can be used to loop through array elements. Array numbering starts from 0 in Java script. Therefore, the name of the array is the second element of the array. As a result, the last element of the array is the total size of the array minus 1.
smithcruise23 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Size of javascript array?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11386 seconds with 12 queries