473,569 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14172
wrote on 08 okt 2006 in comp.lang.javas cript:
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?selLi st=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.javas cript:
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?selLi st=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.javas cript:
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1671
by: palmiere | last post by:
Im trying to do the following: I have 2 select boxes, both are pre populated with data. The first box is a single select box, the 2nd is a multiple select box. Depending on the 1st selection, I want to have multiple values in the second select box highlighted. ie box 1 <select name=type>
7
7887
by: Felix Natter | last post by:
hi, I have a php-Script which gets passed a Boat-ID and this is used to mark an element in a <select> as the default: <select name="boote" multiple="multiple" size="5"> <option value='43'>Aisha</option> <option value='40'>Amsterdam</option> <option value='55'>Asmaa</option> <option value='20'>Beau Rivage</option> <option value='48'>Blue...
3
1992
by: Disco-181 | last post by:
Hi, I have a script which isn't working in Mozilla based browser for some reason. I'm trying to run two functions from the body onload tag and it simply isn't happening. I have a cascading menu, where the primary dropdown selection determines the contents of a second dropdown. This is triggered by a function in the onchange tag of the...
2
3639
by: areef.islam | last post by:
Hi, I am kinda new to javascript and I am having this problem with selecting multiple options from a select tag. Hope someone can help me out here. here is my code /////////////////////////////////////////////////////////////////////////////////////// <form action="whatever.php" method="post"> <select name="zip_code"...
2
4518
by: ggk517 | last post by:
I have a script like below: ------------------------------------------------------------------------------------------------------------------------ <html> <head> <title>TEST</title> <script language="javascript> <!-- function masking () {
4
3993
by: bansh | last post by:
Hi all, As question title I need a javascript which provides the facility to make multiple selection without holding control key. Means I how is it possible to make multiple selection/deselction just clicking over list box items. Thanks
1
2069
by: shidram | last post by:
Hello sir, I have problem while using javascript with HTML multiple selection tag, I want to write javascript in such a way that if a I change the option by clicking on the radio button on html page, the values in the multiple selection box will be different... I mean i have to sets of lists, one for Buy and one for Sell.. I have taken two...
92
4651
by: bonneylake | last post by:
Hey Everyone, Well i was hoping someone could explain the best way i could go about this. i have a few ideas on how i could go about this but i am just not sure if it would work. Right now i have a form where you can add and delete multiple serial information. This works wonderful. But now for every serial information i add i need to be...
58
8029
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also the parts section an i seem to be having trouble. When i try to insert into the parts section i get the error Invalid character value for cast...
482
27423
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. what i am trying to display previously entered multiple fields. I am able to get my serial fields to display correctly, but i can not display my...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.