How do I reference this select?

J

jmDesktop

Hi, I am trying to reference this select:

<input type="hidden" name="grade_itemid" value="<?php
p($selectedgrade_item) ?>" />
<input type="hidden" name="sesskey" value="<?php p($USER-
sesskey) ?>"/>
<input type="hidden" name="action" value="excepts" />
<select name="members[]" size="15" multiple="multiple">

I am trying to get to "members[]". I have this:

getElementById('form3')['members[]'].length = username.length;

but it doesn't work.

Thank you for any help.
 
H

Hendri Kurniawan

Hi, I am trying to reference this select:

<form id="form3" method="post" action="exceptions.php">
<input type="hidden" name="id" value="<?php p($course->id) ?>" />

<input type="hidden" name="grade_itemid" value="<?php
p($selectedgrade_item) ?>" />
<input type="hidden" name="sesskey" value="<?php p($USER->sesskey) ?>"/>

<input type="hidden" name="action" value="excepts" />
<select name="members[]" size="15" multiple="multiple">

I am trying to get to "members[]". I have this:

getElementById('form3')['members[]'].length = username.length;

but it doesn't work.

Thank you for any help.


I am assuming that you want to find out the number of options in the
select element.
getElementById('form3')['members[]'].options.length =
username.length;

Note the "options"

Hendri Kurniawan
 
H

Hendri Kurniawan

I am assuming that you want to find out the number of options in the
select element.
getElementById('form3')['members[]'].options.length =
username.length;
Note the "options"

Why? The select element itself has a length property which is equal to
the number of options.

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-5933486>

Hmm you are right. never tried that before. Always options...
Well I should revoke my answer then.

I'm now GUESSING that the elements returned from
getElementById('form3')['members[]']
is actually an array of elements (by where he have multiple
'members[]' elements.

Hendri Kurniawan
 
T

Thomas 'PointedEars' Lahn

jmDesktop said:
Hi, I am trying to reference this select:
^
Make a decision whether to use XHTML or HTML in one document. I recommend HTML.

http://validator.w3.org/
<input type="hidden" name="grade_itemid" value="<?php
p($selectedgrade_item) ?>" />
<input type="hidden" name="sesskey" value="<?php p($USER-
sesskey) ?>"/>
<input type="hidden" name="action" value="excepts" />
<select name="members[]" size="15" multiple="multiple">

I am trying to get to "members[]". I have this:

getElementById('form3')['members[]'].length = username.length;

document.forms['form3'].elements['members[]']

should work when the `id' attribute is supported. For backwards
compatibility, use the same syntax but the `name' attribute instead.

You don't need to give the form a name or an ID if you are trying to
reference it from one of its controls or from itself. Use the `form'
property of the HTML element object of the form control, or `this'
within an event handler attribute of the `form' element instead.

Why `length', and what is `username'?


PointedEars
 
R

RobG

[...]
I am assuming that you want to find out the number of options in the
select element.
getElementById('form3')['members[]'].options.length =
username.length;
Note the "options"
Why? The select element itself has a length property which is equal to
the number of options.

Hmm you are right. never tried that before. Always options...
Well I should revoke my answer then.

I'm now GUESSING that the elements returned from
getElementById('form3')['members[]']
is actually an array of elements (by where he have multiple
'members[]' elements.

No need to guess, read the spec:

"Returns the Element whose ID is given by elementId. If no such
element exists, returns null. Behavior is not defined if more than one
element has this ID."

<URL: http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-getElBId >

getElementById should not return more than one element, though if more
than one element has the same ID (which would be invalid for HTML), it
seems the first will be return though I wouldn't ever depend on that.

If the element is a select, then it will have an options property,
which is an HTML collection (NodeList), not an Array.

<URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-30606413 >
 

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,159
Messages
2,570,879
Members
47,414
Latest member
GayleWedel

Latest Threads

Top