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

Multiple selection through javascript

P: n/a
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
Share this Question
Share on Google+
3 Replies


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

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

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