471,873 Members | 1,837 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 software developers and data experts.

How do I reference this select?

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
4 1564
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
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
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
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.

Similar topics

7 posts views Thread by Wolfgang Kreuzer | last post: by
2 posts views Thread by David Zuckerman | last post: by
11 posts views Thread by Just Me | last post: by
1 post views Thread by Tony Johansson | last post: by
5 posts views Thread by Michael Russell | last post: by
6 posts views Thread by jan.schaak | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.