Multi-select ListBox and Select All


I'm having an issue with some JS code for IE6 (no need for x-browser) and multi-select listbox.

I'm trying to implement a Select All button.

Current code is :

function SelectAll(obj)
for (var i = 0; i < obj.options.length; i++)
obj.options[i].selected = true;

which logically seems to work.  The problem I have is that this does not seem to work until I click the multi-select again.  It seems that although the options are marked as selected, the screen does not update to reflect this until something triggers it (in this case trying to click in the select box again).

Has anyone else come across this?  If so, is there any way around it?  I tried adding obj.focus(); to the end of the function but this didn't seem to do it.

Chris Disley
Senior Analyst Developer
Barlow Lyde & Gilbert LLP
4/7/2008 12:53:20 PM 24353 articles. 2 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 13

How are you calling it?  This seems to work:

   <input id="Button2" type="button" value="button"  onclick="SelectAll(Select1)"/>
    <select id="Select1" multiple="multiple" >
Steve Wellens

My blog
4/7/2008 1:03:02 PM

Apologies.  Schoolboy error.

Was trying to call it from the onclick of the listbox itself by implementing an 'All' option.  Was a daft idea.  When I switched to the more sensible idea of using a button, it worked fine.  Thanks for your time anyway though.

Chris Disley
Senior Analyst Developer
Barlow Lyde & Gilbert LLP
4/7/2008 1:28:00 PM

Similar Artilces:

Using selected values from a Multi Select Listbox in a SQL query
I have seen a few post concerning this but don't really understand fully as I am new to this.  I would appreciate any help 1) First I loop through the Listbox control and get the selected values: Dim li As ListItemFor Each li In lbPClass.Items If li.Selected = True Then strPC += li.Value & ", " End If Next Label5.Text = strPC The resulting string looks something like: 101, 102, 100 ,    I get rid of the last space and "," with the following statement Label6.Text = Left(Label5.Text, Trim(Len(Label5.Text) - 2)) 2) I would then like to ...

Hi! I remember seeing an example where you can do a select from a nested select, but I cannot seem to make it work. So it would be something like this: select max( name ) from ( select name from customer union select name from vendor ) Was I dreaming I saw that? Thanks! D In article <4500243f@forums-2-dub>, says... > Hi! > > I remember seeing an example where you can do a select from a nested > select, but I cannot seem to make it work. No, you weren't. Try (UNTESTED!) adding a...

Pre select records in multi select listbox using FindbyText
Hi Everyone, I am having problems in preselecting the multiselect listbox depending on the value in database. I have listbox for displaying all the languages and want them to preselect values from database before updating them. Database field: language stores the value along with delimiters like French;Dutch;Spanish. I would like to separate the delimiters and pre-select the values in listbox (lbLanguage). I am using datareader. Please let me know what is wrong in the following code. My Code: string langList=dreader[19].ToString(); string[] langArray=langList.Split(';')...

DataGrid Rollover Colors, select single, select multiple rows client side
Iam just adding some more lines to JakeJeck's post Put this in a class file         public static DataGridItem ApplyRowRollover(DataGridItem item , string MouseOverColor , string MouseOutColor, string MouseClickColor )         {             item.Attributes.Add("onmouseover", "ChangeColorOver(this,'" + MouseOverColor + "','" + MouseClickColor + "');");           ...

Why is the select saying selected after an item is selected?
This was a whitelisting issue due to a software upgrade at hostgator..  Nothing wrong with my code..Scot King SEO Software Tool | Search Engine Optimization"Get your page rank high"  huh? It is smart to put your question in the body and not just in the title. Have no idea what your question is or if it even a question.Eric | Twitter epascarello | LinkedIn use thisddl.options[ddl.selectedIndex].selected = false; //Clear the selection ddl.options[1].selected = trueMAKMark as Answer if this reply helps youMVP ASP/ASP.NetASP.Net Hosting : Host DepotMy Sit...

Problems selecting the selected item in a Listbox
Hi All,I've got two listboxes which I want to allow a user to move items from one to the other. I do the population of the first list during the initial page load and bind the results to the first listbox. I have a button which does the move of the selected item to the second listbox.The problem is when I select an item then click the move button it always moves the first item in the list even if that item is not selected, and never moves the selected item.I've checked that during the postback the listbox is not being repopulated, and it isn't. Any help very much appreciated! thanks....and t...

Multi Select Listbox...
Hey all- I am have big problems with this. For some reason, I cannot get this to work. Anyone know why? It's in the click event of a button with causesvalidation = false. Any idea? Dim li As ListItem For Each li In lstProgramsAvl.Items If li.Selected Then Dim bla As String = li.Text.ToString Response.Write(bla) 'Response.Write(li.Text.ToString) Else Response.Write("Nothing selected") End If Next Thanks, Doug It only happe...

syntax: if last selected item in listbox is and is/not selected??
Hi i currently have this event behind a button, but i want to add another variable 'strNames' that carries out the same behaviour as 'strValues' but i want it to insert the word 'and' between the two last selected items in the listbox aswell as adding a fullstop after the last item. I am not sure what the c# code is to say 'not last selected item' either.....?? So far i have...(but not sure if on the right lines).   try{ string strValues = ""; string strNames = ""; foreach (ListItem item in authorSelectionListbox.Items){ i...

Selecting Items in a multiple selection ListBox that is in a DataGrid?
Is is possible to select multiple items of a listbox that is in the EditItemTemplate of a DataGrid? When someone goes to the edit button on a DataGrid (using the standard OnEditCommand for editing) I want there to be a multiple selection listbox that already has the stored values selected. I have this working for dropdownlist but I cannot get it to work for multiple selection listbox. I am not sure where to put the code that does the selections, I tried to put them on the OnEditCommand but when I use e.Item.FindContol it doesn't find the listbox. Any help would be great! Hi, Can you po...

cannot show selected in databound multiple select listbox
I have a databound, multiple select listbox. I need to have pre-selected items (pulled from DB) shown in an update form.Everything below works as expected until #6 where I try to have the multi-select listbox display the selected items in an edit form.1. form code --i'm populating the listbox with items from the 'jobs' table using a select statment Code:<td align="right" valign="top">*Community Jobs Available</td> <td valign="middle" style="width: 323px"><asp:ListBox ID="choosejobs" runat="server" DataSourceID="SqlDataSource1" DataTextField="job_title" DataValu...

Deleting all selected items in a multiple-select listbox
I am trying to write a simple loop that is called on a button click event so that any selected items in my multiple-select mode listbox are removed. I cannot seem to get it to work and I would be grateful for help. The code below only removes one item when I use it, even if more than one item is selected in the listbox. Many thanks. 1 2 Dim i As Integer 3 For i = ListBox1.Items.Count - 1 To 0 Step -1 4 If ListBox1.Items(i).Selected Then 5 ListBox1.Items.RemoveAt(i) 6 End If 7 Next    ...

Client side datagrid selection?
Hi.. In my web page, i have a datagrid. If the user selects any row in the datagrid, i want to select that row. How to do this using javascript? I'm not clear on what you mean by selecting the row with javascript.  Do you want the row highlighted?  You would need to add an onclick event to each row, and adjust the styles of the row that received the click. I want the row to be highlighted when the user selects the row. Thank You Hi venkatzeus, According to your requirement, the following code is for your reference. I hope it is helpful to you. <html xmlns="ht...

value of multi select listbox
Hey Guys, I have 2 listboxes on a page used for adding and removing from an available list to a selected list. I have the value property of my available list set to id's from a database. When i select multiple items at the same time from listbox 1 and move them to listbox 2, i am always getting the same value for all of the items in listbox 2. Whats worse is that instead of getting the datavaluefield, i get the index of listbox 1 as the value field. For example: I choose items 2,3,5 from listbox 1 and when they are moved to listbox 2, my item.value is always 2 instead of having...

Select option selection
I'm created a gridview of websites, in one column, and use the gridview's 'selection' featue in the next column. When I click the 'selection' link I tried to get the website by using: Dim key As String = grvPrivacy.Rows(e.RowIndex).Cells(1).Text but it said it was not part of the webcontrol for selection. How do I get cell so that I can read it? thanks   Looks like your grabbing the select option and not the first cell  try  Dim key As String = grvPrivacy.Rows(e.RowIndex).Cells(0).TextwerD, MCSD VB.Net Hi, gmcghee: There are several ways...

Web resources about - Multi-select ListBox and Select All -

[Android M Feature Spotlight] Multi-Select To Merge, Delete, Or Share Contacts
The updated contacts app in Android M has a nifty little trick up its sleeve. You can select multiple contacts from the main list to merge, delete, ...

Rostelecom Selects Infinera for Multi-Terabit Intelligent Transport Network(TM) in Russia
SUNNYVALE, CA and MOSCOW, RUSSIA(Marketwired - Oct 9, 2013) - Infinera (NASDAQ: INFN), a leading provider of Intelligent Transport Networks and ...

TDS Selects ARRIS MOXI® Whole Home Solution to Give Subscribers Personalized, Multi-Room... SUWANEE ...
SUWANEE, Ga., Oct. 12, 2015 /PRNewswire/ TDS Selects ARRIS MOXI® Whole Home Solution to Give Subscribers Personalized, Multi-Room Access to Their... ...

Resources last updated: 1/16/2016 4:44:55 PM