By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,466 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,466 IT Pros & Developers. It's quick & easy.

How do I reference this select?

P: n/a
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.

Aug 10 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Aug 10, 1:03 pm, jmDesktop <needin4mat...@gmail.comwrote:
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

Aug 10 '07 #2

P: n/a
On Aug 10, 1:18 pm, Hendri Kurniawan <hckurnia...@gmail.comwrote:
[...]
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-HTM...tml#ID-5933486 >
--
Rob

Aug 10 '07 #3

P: n/a
On Aug 10, 2:10 pm, RobG <rg...@iinet.net.auwrote:
On Aug 10, 1:18 pm, Hendri Kurniawan <hckurnia...@gmail.comwrote:
[...]
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>

--
Rob
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

Aug 10 '07 #4

P: n/a
On Aug 10, 2:56 pm, Hendri Kurniawan <hckurnia...@gmail.comwrote:
On Aug 10, 2:10 pm, RobG <rg...@iinet.net.auwrote:
On Aug 10, 1:18 pm, Hendri Kurniawan <hckurnia...@gmail.comwrote:
[...]
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>
--
Rob

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-Cor...ml#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-HTM...ml#ID-30606413 >
--
Rob

Aug 10 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.