• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Moving options between listboxes complicated by JSTL

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two list boxes and I want to be able to move selected options between each other before submit. I am having trouble coming up with a script to do this. Anyone know where I can find one?

Its a bit confusion because the initial population is done with JSTL. The ID's are primary keys to the DB, so they are not sequential and can change between dialog startup.

Here is my code from the JSP:

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use of the JSTL offers no complications as that is evaluated on the server prior to sending the response to the browser. JavaScript on the page has no idea that the JSTL was used and just sees the resulting DOM.

So what's the real problem? Under what conditions do you want to "move" elements around?
 
M Burke
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to move the selected options between the list boxes when the user clicks the left --> or right <-- buttons.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so that sounds fairly straightforward. You are planning to use jQuery to help make the JavaScript much simpler, right?

Off the top of my head:
  • A click handler on the button(s) is established at document-ready.
  • The click handler selects the options in the select element that are selected.
  • The result of the selection is moved to the other select element.


  • Give the code a try.

    By the way, if you are not using the Browser Tools to inspect the DOM and monitor the JavaScript console, then you need to start. This will show you the DOM as the browser sees it -- the server side markup with the JSTL is irrelevant.
     
    M Burke
    Ranch Hand
    Posts: 434
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    That process flow makes sense, thanks. I can't use jQuery. It's a school project and none of the other members know jQuery, so I have to keep it base.

    I developed a solution. If anyone sees any holes in what I did, please let me know.



     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic