ListBox item disable?

ListBox item disable?

I have a popup edit window that has a query generated ListBox of items that have "Amount" attributes to them. On the form, the user enters a "Payment Amount" as an input. They then have this dynamically generated list of items to chose to pay for (let's call them "costs"). I have created expressions at the bottom of the page that use the OnChange event of both the Payment Amount input and the ListBox to refresh and calcutate the "Total Applied" and "Total Remaining" values. So, scenario is like this:

User launches popup to make a payment. They type in a Payment Amount. The OnChange action is kicked off and stores the Amount in a local variable "RemainingAmount". Now, they come to the listbox that is generated from a query. Each time they click an option, the same action is called for the OnChange event as for the Payment amount. The action grabs the Payment Amount from the edit widget input, stores it as local RemainingAmount, then cycles through a ForEach loop and subtracts any amounts from any selected list box items This difference is updated and stored as RemainingAmount, and Ajax refreshed on the client page. This gives the affect of the Amount Remaining on the bottom of the page tracking any Payment Amount monies that have not been "allocated" to a "cost" yet.

So far, this all works great. What I would like to add to this, however, is to dynamically "disable" or remove from the list box any itmes once all money has been allocated. So, if I put in $50 as my Payment Amount, then I select an item for $20, then another $30 item, I want the listbox to now prevent me from being able to select any additional options, whether by disabling additional selections, or some how hiding them from the list.

Let me first say two things... I am not concerned with the amount going negative. I only want to block selections AFTER the RemainingAmount has become <= 0. So, if I enter payment amount of $50, I select an item for $45, I still want all remaining selections available. Event if I select another $10 item (now putting me at -$5), that is okay. I still want to allow it. It is AFTER that $10 allocation that I want to block it. I don't need help with this part, just letting you know it is a strange sounding condition, and I don't want people to get hung up trying to worry about that condition in responding.

Second, I know most people will be wanting to say "Why not just let it calculate the total as they click items". All I can say is that I am working with a legacy db structure that has some neuances to it that require me to do it this way. The resulting transaction is actually going to be writing data to about 3 different tables, and I have to do it this way to keep the data integrity.

Now, anyone have any ideas :-)
think you said it yourself.
just remove the unavailable items from the list and refresh the dropdown?

Yeah, what I am finding with that, though, is that with a ListBox, it won't let them "deselect" the item. So, what I am encountering is that if they pick only one item that takes them to the $0 limit, it now truncates the listbox to the one item, and has it selected. I cannot "deselect" that one item to get the onchange to kick off again and repopulate the list if they want to change their selection. Grrr.... It's always something :(

Any other ideas? Bottom line is I need to dynamically present the user with a list of choices. I then need to be able disable other choices within that same selection based on the ones they have selected already.