468,244 Members | 1,788 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,244 developers. It's quick & easy.

Multiple selection through javascript

Hello

I have a multiple select list as follows:

<select name="selList" multiple>
<option value="1"Item 1</option>
<option value="2"Item 2</option>
<option value="3"Item 3</option>
</select>

When the form in which this select list is submitted, I wish to select
all items in the list. Therefore on form submit, I call a javascript
which does the following:

for(i = 0; i < document.forms[0].selList.length; i++)
document.forms[0].selList[i].selected = true;

Before the submit is done, I can visually see on the page that all
items in the list have been selected.

However when I retrieve the request values on the next page, I get only
the last element in the list. What am I doing wrong? Any suggestions
would be welcome.

Thanks
Swetha

Oct 8 '06 #1
3 13986
wrote on 08 okt 2006 in comp.lang.javascript:
I have a multiple select list as follows:
[..]
However when I retrieve the request values on the next page, I get only
the last element in the list. What am I doing wrong? Any suggestions
would be welcome.
Try:

========= test.html ==========
<form>
<select name="selList" multiple>
<option value="1"Item 1</option>
<option value="2"Item 2</option>
<option value="3"Item 3</option>
</select>
<input type=submit>
</form>

<script type='text/javascript'>

</script>
==============================

The result after submission on the address bar is,
with the first two selected:

test.html?selList=1&selList=2

It seems to me you make a mistake in your "retrieving" code,
and do not show the code of that.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 8 '06 #2
Yes that's right! I was making a mistake retrieving the values.. It
works fine now.

Thanks
Swetha

Evertjan. wrote:
wrote on 08 okt 2006 in comp.lang.javascript:
I have a multiple select list as follows:

[..]
However when I retrieve the request values on the next page, I get only
the last element in the list. What am I doing wrong? Any suggestions
would be welcome.

Try:

========= test.html ==========
<form>
<select name="selList" multiple>
<option value="1"Item 1</option>
<option value="2"Item 2</option>
<option value="3"Item 3</option>
</select>
<input type=submit>
</form>

<script type='text/javascript'>

</script>
==============================

The result after submission on the address bar is,
with the first two selected:

test.html?selList=1&selList=2

It seems to me you make a mistake in your "retrieving" code,
and do not show the code of that.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 8 '06 #3
wrote on 08 okt 2006 in comp.lang.javascript:
Yes that's right! I was making a mistake retrieving the values.. It
works fine now.
[Please do not toppost on usenet]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 8 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Felix Natter | last post: by
3 posts views Thread by Disco-181 | last post: by
2 posts views Thread by areef.islam | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.