what shall i do when the form name is an array?

F

frey

i have two parts of code here
this is a javascript:
function addThirdTierCategory(){
var length = document.form.selectedCategory.options.length
var maxNum=10;
if(length >= maxNum){
alert('maximum selection exceeded');
return;
}
....................................
.................................................

the second line:
var length = document.form.selectedCategory.options.length
if i need to change the select box name from
selectedCategory into selectedCategory[]

like the following html code

<td colspan="2"><select multiple="multiple" size="10"
name="selectedCategory[]">
</select></td>

so later i could submit this form to a php file then i can read the
multiple selections, the problem i am having now is the select box
named "selectedCategory[] " is part of the multielevel selection box
which works with javascript, if i change the name in javascript: which
is from

document.form.selectedCategory.options.length
into
document.form.selectedCategory[].options.length

it reports error,

any one can give me some advice on it? thank you very much!!
 
R

RobG

frey said:
i have two parts of code here
this is a javascript:
function addThirdTierCategory(){
var length = document.form.selectedCategory.options.length

You have an error here -----------^ that should be forms. I'll guess
it's just a copy/paste error.

[...]
so later i could submit this form to a php file then i can read the
multiple selections, the problem i am having now is the select box
named "selectedCategory[] " is part of the multielevel selection box
which works with javascript, if i change the name in javascript: which
is from

document.form.selectedCategory.options.length
into
document.form.selectedCategory[].options.length

document.forms['selectedCategory[]'].options.length

See the group faq:

<URL:http://www.jibbering.com/faq>
 
R

RobG

RobG said:
You have an error here -----------^ that should be forms. I'll guess
it's just a copy/paste error.

Ooops, seems the name of your form may be 'form', so ignore the above.
[...]
[...]


document.forms['selectedCategory[]'].options.length

And if 'form' is your form name, then:

document.form.elements['selectedCategory[]'].options.length

will work somewhat better. :)

<URL:http://www.jibbering.com/faq/#FAQ4_39>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top