Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on select-box options

 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XSLT might do it quickly and easily.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roger F. Gay
Ranch Hand
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks !
My mistake - indeed, I should have asked about 'replace' rather than 'edit'.

Your reply helped a lot, thank you so much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic