473,809 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unselecting specific item in listbox

Hi,
I have a listbox set up so users can select multiple choices. I want
to limit them so they can choose no more than 4 at a time. I have set
up javascript code to do the check on the number of choices selected
but what I want to do is if they choose more than 4 (i.e. 5), I want
to unselect the last item they selected. I cannot figure out how to
determine which was the last item selected.

function HasExceededMaxi mumYearWeekCoun t()
{
var count = 0;
for (index = 0; index < fmDetailQuery.l stYearWeek.opti ons.length;
index++)
{
if (document.all.l stYearWeek.opti ons(index).sele cted)
{
count++;
}
}

if (count 4)
{
alert("You can only select a maximum of 4 year weeks at a
time.")
return false;
}

return true;

}

I have tried doing a check on this value:

fmDetailQuery.l stYearWeek.sele ctedIndex

but it always returns me the first item in the listbox that was
selected (i.e. the one at the top of the list that was selected). I
want the last item the user selected, is there a way to determine that?
Aug 8 '08 #1
5 2317
On Aug 8, 2:12 pm, Doogie <dnlwh...@dtgne t.comwrote:
Hi,
I have a listbox set up so users can select multiple choices. I want
to limit them so they can choose no more than 4 at a time. I have set
up javascript code to do the check on the number of choices selected
but what I want to do is if they choose more than 4 (i.e. 5), I want
to unselect the last item they selected. I cannot figure out how to
determine which was the last item selected.
<snap>
You will need onClick event on each checkbox to do that...

Aug 8 '08 #2
On Aug 8, 9:15*am, GArlington <garling...@tis cali.co.ukwrote :
On Aug 8, 2:12 pm, Doogie <dnlwh...@dtgne t.comwrote:Hi,
I have a listbox set up so users can select multiple choices. *I want
to limit them so they can choose no more than 4 at a time. *I have set
up javascript code to do the check on the number of choices selected
but what I want to do is if they choose more than 4 (i.e. 5), I want
to unselect the last item they selected. *I cannot figure out how to
determine which was the last item selected.

<snap>
You will need onClick event on each checkbox to do that...
It's not a checkbox, it's a listbox. I need a way to determine the
last item selected in the list box.
Aug 8 '08 #3
On Aug 8, 3:23 pm, Doogie <dnlwh...@dtgne t.comwrote:
On Aug 8, 9:15 am, GArlington <garling...@tis cali.co.ukwrote :
On Aug 8, 2:12 pm, Doogie <dnlwh...@dtgne t.comwrote:Hi,
I have a listbox set up so users can select multiple choices. I want
to limit them so they can choose no more than 4 at a time. I have set
up javascript code to do the check on the number of choices selected
but what I want to do is if they choose more than 4 (i.e. 5), I want
to unselect the last item they selected. I cannot figure out how to
determine which was the last item selected.
<snap>
You will need onClick event on each checkbox to do that...

It's not a checkbox, it's a listbox. I need a way to determine the
last item selected in the list box.
I have done something like that a long time ago, I think that the
trick was in (still) onClick event, it returned info about which item
was clicked (and therefore selected/deselected)...
Aug 8 '08 #4
pr
Doogie wrote:
On Aug 8, 9:15 am, GArlington <garling...@tis cali.co.ukwrote :
>On Aug 8, 2:12 pm, Doogie <dnlwh...@dtgne t.comwrote:Hi,
>>I have a listbox set up so users can select multiple choices. I want
to limit them so they can choose no more than 4 at a time. I have set
up javascript code to do the check on the number of choices selected
but what I want to do is if they choose more than 4 (i.e. 5), I want
to unselect the last item they selected. I cannot figure out how to
determine which was the last item selected.
<snap>
You will need onClick event on each checkbox to do that...

It's not a checkbox, it's a listbox. I need a way to determine the
last item selected in the list box.
onclick in the select element then. To determine which item(s) is/are
selected, look at the selected property of each option. Simple example:

var i, l, a = [];
for (i = 0, l = selectElement.o ptions.length; i < l; i++) {
if (selectElement. options[i].selected) {
a.push(i);
}
}
window.alert("S elected items were " + a.join(", "));

Set selected to false to unhighlight an option. You might like to
consider check boxes, however; multiple selects can be a pain for the
end user - eg. try using them with just the keyboard.
Aug 8 '08 #5
pr
pr wrote:
onclick
Sorry, should be onchange
>
[code]
ie. by comparing an array denoting previously selected options with the
list of currently selected options, you know which option(s) the user
last selected.
Aug 8 '08 #6

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

Similar topics

4
22630
by: Peter Moscatt | last post by:
I am having trouble understanding the methods for the Listbox from Tk. If I was to select at item in the list using a mouse click (have already created the bind event) - what method returns the text of the selected item ? Pete
3
3617
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name in the subform. Is it possible? How do I do this? Thanks in advance. Paul from Slovakia
10
21902
by: SueB | last post by:
Hi. Is there a way to "unselect" items in a listbox, programmatically? Here's what I want to do (and I've been trying to to this while debugging the form, but I've been unsuccessful) ... I have a form with two listboxes. The form, also, has two option buttons in an options group: 1 button for
1
1777
by: honeybee | last post by:
How to get the item value from a specific Item Index in the listbox?
4
6144
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the extra item just doesn't get added to the DropDownList: ============================================= <script runat="server"> Sub Page_Load(..........) Dim dSet As DataSet Dim sqlConn As SqlConnection
6
1361
by: jesse07 | last post by:
I have 6 seperate listbox and I want the user to select 1 value from 1 of the 6 boxes. The problem is after the user clicks the listbox1 then listbox2, listbox1 still says highlighted. I want to "unclick" or deselct the line from listbox1 when the user selects listbox2. Any suggestions?
8
15446
by: jh | last post by:
I'd like to copy/paste into a listbox during runtime. I can do this for a textbox but can't figure out how to accomplish this for a listbox. Any help? Thanks.
2
11122
by: gnosys | last post by:
In ASP.Net 1.1 using C#, I'm trying to dynamically change the background colors of certain listbox items based on some criteria. For example:
3
3472
by: Sweetiecakes | last post by:
Hi I have an string array containing file paths. I have added them to a ListBox with AddRange(); When I delete an item from the ListBox, how can I delete the same item from the original array? Thanks
0
9722
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10391
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10121
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4333
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
3
3015
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.