Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MultiSelect and JavaScript

 
sudharshan tettu
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
In a multi select box , unless user select option(s) , will it not be possible to send the values back to the server ,in the form of request parameter

For example i have dual multi select box where user can add his selection from one list box to the one on right by clicking on a button or remove [it re-populates the one on left ]
in this scenerio when i access the value of the select box , i dont get any values there unless if its selected

String[] destination= (String[]) request.getParameter("destination");

"destination" is the second list box , it has options but not able to get it like above ,unless those options are selected

Is there any way of achieving this using javascript enumerations

Thanks
 
Dawn Charangat
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.. it is actually a round about way, how I achieved this... you can try the same..

On submit, invoke a javascript function, which will iterate through your second multiselect box, and set "selected=true" on all the options. Then you go ahead and do the form.submit()

Thus, on submit, all the values in the second select box would be submitted along with the form, and you can get them as request.getParameterValues()

cheers,
Dawn.
 
sudharshan tettu
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thanks for the reply
I am doing it in the same way ,but as you do selected = true they all get selected [i mean they appear to be selected] but
it should not be that way ,is there any way
 
Dawn Charangat
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way, is to create a hidden field, and again, just before submitting the form, iterate through your second multiselect box, and add the option values to this hidden field [comma separated or something like that], without actually selecting any of the options - and then submit the form. In server side, you can get the value of the hidden field, and hence know what are the options in that second box.

By the way, just curious, what is stopping you from using the first solution?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic