Meaningless Drivel is fun!*
The moose likes HTML, CSS and JavaScript and the fly likes Question on select-box options Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Question on select-box options" Watch "Question on select-box options" New topic
Author

Question on select-box options

Sol Mayer-Orn
Ranch Hand

Joined: Nov 13, 2002
Posts: 311
Hi,

Would someone please happen to know if there's a javascript function for 'bulk add' or 'bulk copy' on select-box options ?

In detail, I have a javascript code which dynamically changes the list of options is some select box.
Currently, I'm adding options into my select box, one at a time.
It works, but with very big lists, the effect is ugly (you kind of see the 'animation' in the browser, feeling how it gets filled one option at a time:


Is there a way to add all values in 'one go' ?
Something like:
myForm.mySelectBox.options.addList( myValues) // imaginary code

Thanks
Roger F. Gay
Ranch Hand

Joined: Feb 16, 2007
Posts: 376
XSLT might do it quickly and easily.


Correlation does not prove causality.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61309
    
  66

I think that he wants to do this in Javascript after the document loads. Otherwise, a server-side solution like XSLT or JSP would solve the issue.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Roger F. Gay
Ranch Hand

Joined: Feb 16, 2007
Posts: 376
You can do XSLT in javascript; least in IE. I haven't done it in any other browser yet; but believe it can be done.
Sol Mayer-Orn
Ranch Hand

Joined: Nov 13, 2002
Posts: 311
Thanks for replying.
Note my list needs to change dynamically, on the client side (for the sake of discussion, imagine the select-box shows a list of *cities*, which needs to change dynamically whenever user selects a country/state... and assume there are about 300 countries per state.
Admittedly it's ugly to have such a large select-box, but these are current requirements).

All I'm trying to do is replace that entire list of cities in 'one go' instead of 1 option at a time.

Would XSLT really help in that case?
If so, could anyone please refer me to further related buzz-words / tutorials on the subject ( just googling for XSLT and Javascript is problematic when one doesn't know exactly what to look for...)

Thanks again
Roger F. Gay
Ranch Hand

Joined: Feb 16, 2007
Posts: 376
It will be an easier problem if you mean to replace the list. No need for XSLT. Replacing the entire list is not the same problem as modifying the list. If you store the individual lists in the same form they are used; as a select / options list, you can use DOM programming in javascript for the replacements.

If someone knows of a "join" function in DOM programming, I'd like to hear about it. But you should be able to remove the old select and "appendChild" a replacement. Where are you storing that information now? Is it all in the web page?
Sol Mayer-Orn
Ranch Hand

Joined: Nov 13, 2002
Posts: 311
Thanks !
My mistake - indeed, I should have asked about 'replace' rather than 'edit'.

Your reply helped a lot, thank you so much.
 
GeeCON Prague 2014
 
subject: Question on select-box options