Multiple selection through javascript

S

swethasivaram

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.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
 
E

Evertjan.

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.
 
S

swethasivaram

Yes that's right! I was making a mistake retrieving the values.. It
works fine now.

Thanks
Swetha

Evertjan. said:
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.
 
E

Evertjan.

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]
 

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,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top