473,385 Members | 1,342 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,385 software developers and data experts.

How can we deselect options in html dynamically (using javascript)

when i used the statment
for(var i = 0; i < menu.length; i++)
{
menu.options[i].selected = "false";
}

to deselect all the options within a list, it surprisingly selected all
the options. I tried another option like

menu.options[i].removeAttribute("selected");

it also didnt work without any error message.

what would be the solution of this problem. i want to deselect all the
options of a list dynamically.

Mar 8 '06 #1
2 11403
VK

ahmad wrote:
when i used the statment
for(var i = 0; i < menu.length; i++)
{
menu.options[i].selected = "false";
}

to deselect all the options within a list, it surprisingly selected all
the options. I tried another option like

menu.options[i].removeAttribute("selected");

it also didnt work without any error message.

what would be the solution of this problem. i want to deselect all the
options of a list dynamically.


AFAIK select-multiple requires physical user interaction (Ctrl+Click
etc.) to make multiple selections. This interface is not
programmatically exposed - it's part of interface protection.

Together with your other post (styling separate select options) I would
suggect either to change the whole concept (whatever it is right now)
or to use a DHTML widget instead of conventional <select>.

Mar 8 '06 #2
On 08/03/2006 09:24, ahmad wrote:
when i used the statment
for(var i = 0; i < menu.length; i++)
{
menu.options[i].selected = "false";
}

to deselect all the options within a list, it surprisingly selected all
the options.


The selected property is a boolean, and /any/ non-empty string
type-converts to true. So, that assignment might as well have been:

menu.options[i].selected = true;

[snip]

Hope that helps,
Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Mar 8 '06 #3

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

Similar topics

12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
1
by: comp.lang.javascript | last post by:
Using IE5.5+, is it possible to hide options in a select? The following doesn't work: <HTML> <HEAD> <STYLE> SELECT OPTION.orgA{ display:none } .orgB{ display:inline } .orgC{ display:none }
3
by: Notorious | last post by:
The following Javascript line will deselect the currently selected index of a select box for Netscape and Firefox, but will not deselect in Explorer 6. theForm.assignedLic.options.selected =...
3
by: Tony Kim | last post by:
Hi everyone, i have an assignment that needs immediate attention and was hoping i would be able to get some help here. im trying to create 3 option boxes that are linked together. for...
12
by: Russ | last post by:
I'm interested in setting up a web page where live data can be displayed in real-time on the web page. For example: I would like to display a (nice looking) graph of some data value versus time...
6
by: Orchid | last post by:
I have 2 fields with Radio button Data Type, and both fields with more than one options. On Field1, I want the user to select option1, then Field2 is shown and able to select. If the user selects...
7
by: deepagulati | last post by:
Hi, I need an urgent help from you. When we dynamically genrate any list box (Select Box) it shows one default value as selected. Is there any way that we can deselect that value. I...
2
by: kiranmn75 | last post by:
I want to dynamically populate a combo box through javascript. Data is coming from a array. Sometimes data list may contain items in excess of 2000. Explorer takes more than 5 seconds to...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.