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

A

ahmad

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

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

menu.options.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.
 
V

VK

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

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

menu.options.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>.
 
M

Michael Winter

when i used the statment
for(var i = 0; i < menu.length; i++)
{
menu.options.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.selected = true;

[snip]

Hope that helps,
Mike
 

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
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top