• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

get parameters from a dynamic select

 
Ranch Hand
Posts: 30
Hibernate C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to all,
i have the following select tag:



i use javascript to add options to the select and allowing the user to change the order of those options.
The thing is i don't know how to send the options to the servlet (or retrieve the options like getParameter("OrderList")),
i need all the option's text parameters (best to return with values also but not necessarily).
I have read a little about JSON, still not sure if i really need it to accomplish this task.
any ideas or suggestions ?
 
Sheriff
Posts: 67752
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
You have not made what you are trying to accomplish clear. And the fact that options are dynamically generated is a red herring. The state of the <select> element at submission time is all that matters. It makes no difference how it got to that state.

With that in mind, care to restate your requirements?

By default, a <select> element will have the value of the selected option (which defaults to its content if no value is provided) passed using the name assigned to the select. What is it that you want that is different from this?
 
David Avrami
Ranch Hand
Posts: 30
Hibernate C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need the names and the values of the SELECT.
in my servlet the line:
request.getParameterValues("OrderList");
returns NULL although i do have options in the SELECT. (added by javascript)
so i thought maybe it's because initially the select was empty, therefore asking if there is
a different way to get those names and values.

thank for the fast reply.
 
Bear Bibeault
Sheriff
Posts: 67752
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

David Avrami wrote:I need the names and the values of the SELECT.


There is only one name associated with a <select>. WHat other names are you asking about?

And, only one option value can be selected (and hence returned) unless the select is marked as multiple, in which case it becomes a list rather than a dropdown.

in my servlet the line:
request.getParameterValues("OrderList");
returns NULL although i do have options in the SELECT. (added by javascript)


Is one of the options marked as selected?
 
Bear Bibeault
Sheriff
Posts: 67752
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
I'm also a little skeptical that your <option> elements are being added correctly. Even with no option selected, the select should default to the first option.

Have you used a DOM inspector to make sure that the HTML DOM is really that you think it is at the time of submission?
 
David Avrami
Ranch Hand
Posts: 30
Hibernate C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i need the options names and values like if i have a select like:

<select name="OrderList" size="8" id="OrderList" style="direction:rtl; position:absolute;left:500px;top:200px;width:150px;font-family:Courier New;font-size:16px;z-index:32">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
</select>

so in my servlet i could get a List or other object that will contain:
volvo, Volvo
saab, Saab
mercedes, Mercedes

there can be one selected option but i need them all.
maybe one way do to so is to mark the SELECT as multiple and after the user presses the submit button javascript will select all the options and then submit the form to the server?
 
Bear Bibeault
Sheriff
Posts: 67752
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
Nope, you will not be able to get the text content (they're not names, so stop calling them that, it's just confusing) of the options using the select element in any configuration -- the text content of the options is not ever part of the submission. If the values are omitted, the values will default from the text content, but that only works if they're to be the same which is not the case here.

If you want all the options returned, including text content and values, you'll need to create hidden inputs containing the information you want.

You could do this in a submit handler established on the form.
 
David Avrami
Ranch Hand
Posts: 30
Hibernate C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I made a hidden input containing the information i needed in its value.
works great for me.

the hidden input in the html:


the javascript:


thank you for your help.
 
Bear Bibeault
Sheriff
Posts: 67752
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
 
knowledge is the difference between drudgery and strategic action -- tiny ad
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic