• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Another Javascirpt question... looping through arrays

Superwormy

Golden Member
for (var key = 0; key < formobj["category[]"].length; key++) {

var thingama = formobj["category[]"][key];
alert ("it is: " + thingama);

}


Thats what i have... it doesn't work. Basically theres a multiple select box named category[] in an HTML form, the form is passed to javascript with an onsubmit="return FunctionName(this)"

All I want to do is loop through that category array and print out the values... how?
 
What is your form name?

for (var key = 0; key < document.{your form name that the form element belongs to}.category[].length; key++)
 
Right but the actual name of the array is category[], INCLUDING those brackets.

And 'formobj' is what the function takes as the array. It loops through the correct number of times, but I don't know how to refer to each value for each selected thing.

That make sense?


What I really would like is a statement like the foreach ($arrayname as $key => $value) { like PHP / Perl has... does Javascript have this?
 
Back
Top