473,398 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

change multiple in single select

Hi all

how can i manipulate a multiple select into a single select dropdown
field with JavaScript?

thanks

Aug 19 '05 #1
3 5611
document.forms["my_form"]["my_select"].multiple=false;

Aug 19 '05 #2
On 19 Aug 2005 12:39:46 -0700, d.********@gmx.net wrote:
how can i manipulate a multiple select into a single select dropdown
field with JavaScript?


<form name="myForm">
<input type="button" name="myButton" value="Toggle"
onclick="toggle();">
<br>
<select id="myMultiSelectId" name="myMultiSelect" multiple="multiple">
<option>One</option>
<option>Two</option>
<option>Three</option>
<option>Four</option>
</select>
<select id="mySelectId" name="mySelect" style="display:none;">
<option>One</option>
<option>Two</option>
<option>Three</option>
<option>Four</option>
</select>
</form>
<script type="text/javascript">
function toggle() {
if (document.getElementById) {
var myMultiSel = document.getElementById('myMultiSelectId');
var mySel = document.getElementById('mySelectId');
if (myMultiSel &&
(myMultiSel = myMultiSel.style) &&
mySel &&
(mySel = mySel.style)) {

myMultiSel.display = ('none' == myMultiSel.display ? '' :
'none');
mySel.display = ('none' == myMultiSel.display ? '' :
'none');
}
}
}
</script>

It's sort of fragile, if both select elements somehow ended up in the
same state, clicking the "Toggle" button wouldn't toggle them, it
would turn them both on/off.

The other thing you may want to consider is constructing a new select
using document.createElement() rather than swapping two select
elements on the page (especially if the select contains lots of
options and you don't want to replicate them twice).

--
Grant Wagner <sq*******@yahoo.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Aug 19 '05 #3
On 19 Aug 2005 13:41:11 -0700, "Markis Taylor" <do*********@gmail.com>
wrote:
document.forms["my_form"]["my_select"].multiple=false;


<form name="myForm">
<input type="button" name="myButton" value="Toggle"
onclick="toggle();">
<br>
<select name="myMultiSelect" multiple="multiple">
<option>One</option>
<option>Two</option>
<option>Three</option>
<option>Four</option>
</select>
</form>
<script type="text/javascript">
function toggle() {
document.forms['myForm'].elements['myMultiSelect'].multiple =
!document.forms['myForm'].elements['myMultiSelect'].multiple;
}
</script>

Results in really odd behaviour in Opera 8.02 and 7.54u2. You get a
single item select, but it has up/down arrow buttons instead of being
a pull-down menu.

--
Grant Wagner <sq*******@yahoo.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Aug 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dave C. | last post by:
Hello, I have created the following trigger: CREATE TRIGGER tr_UDFTest ON UserDefinedFields FOR INSERT, UPDATE AS DECLARE @foobar varchar(100) SELECT @foobar= foobar FROM inserted IF (...
0
by: rayone | last post by:
Hi folks. I need advice. 2 options, which do you think is the better option to display/retrieve/report on the data. Keep in mind reporting (Crystal), SQL Performance, VB Code, usability,...
9
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and...
2
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...
3
by: imrantbd | last post by:
I need array type name like "destList" must use for my destlist select box,not a single name.Or need a solution to capture multiple value of "destList" select box and send all selected value in php...
7
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Run multiple SQL statements from ASP/ADO to an Oracle 10g. Please help, I'm trying to write an ASP page to use ADO to run a long query against an Oracle 10g database, to create tables,...
2
by: =?Utf-8?B?VGVycnk=?= | last post by:
I have coded multiple select statements in a single stored procedure, and when I execute this procedure on SQL Server Management Express, I correctly get multiple result sets. But, if I try to add...
2
by: Michael | last post by:
It seems that a gridview allows us to delete only a single row at a time. How to extend this functionality to select multiple rows and delete all of the selected rows in a single stroke? just like...
6
by: phpnewbie26 | last post by:
My current form has one multiple select drop down menu as well as few other drop down menus that are single select. Originally I had it so that the multiple select menu was first, but this created...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.