[Javascript] Add/Remove Elements in a Select Box with Ajax

Henrique Rennó henrique.renno at gmail.com
Fri Feb 9 11:24:56 CST 2007


Hello!!!

Some time ago I posted here about trying to make some select box filtering
based in another select box based in data stored in a mysql database. After
days of googling I got a working code using CGI::Ajax module for Perl.

Now I want to do something that made me be stuck again. I'm trying to
add/remove elements from a select box to another but Ajax always updates the
entire destination select box erasing everything it already has. The
CGI::Ajax module works mapping every Javascript function to a perl
subroutine and every time an event occurs it calls a function and executes
the subroutine instead. "id" properties indicate sources and destinations,
where the data come from and where they are going to.

Problem simulation:

- source select box contains: text_1 text_2 ... text_N (N elements)
- do a multiple selection selecting a range namely text_k ... text_k+m
- click in a "add" button that adds all selected elements from source to the
destination select box
- (oh I forgot to add some elements)
- select a new range and click add button again
- the new select is cleared and only the new selected ones are added to it
(i know it happens because a new select is constructed and put inside the
destination "div" tag again)

How I can save the elements so that I could add them again to the
destination select box????
What about removing???  I didn't try it yet, but is it possible to use some
kind of "onkeypressed" event and remove a range of elements (like pressing
DEL key)?????

Thanks!!!!

-- 
Henrique
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20070209/ac0569a2/attachment.htm>


More information about the Javascript mailing list