Non-displayed "Select" list

liunx

Guest
I want to create/populate a multi-selection Select list<br />
and have all of the options "selected". Help here is not<br />
necessary.<br />
<br />
However, I do not want this "form object" to be displayed <br />
but only registered when the form is "submitted". <br />
<br />
Is this possible? If so, what would I need to do in either<br />
HTML or Javascript.<br />
<br />
Thanx...<!--content-->If you don't want a form input to be shown, use <input type="hidden"...<!--content-->When passed, a "hidden" object would only permit one <br />
value, I believe, to be assigned to the object, such as:<br />
myServlet?arg=value1<br />
<br />
I would need to account for multiple values of the same<br />
object name during a submit, (such as "arg", as used here):<br />
myServlet?arg=value1&arg=value2&arg=value3<br />
<br />
Hence my usage of a non-displayed "select" object.<br />
<br />
This is my reasoning for using this particular object<br />
however I don't want to display it as I will be <br />
formulating the object programmatically.<!--content-->Well, it is impossible to have a hidden select list. You could, though, have all of the values in one hidden input, separated by some character(s). Then, when processing the form, use some function to split the string into different variables, or an array (in PHP, you would use split()).<!--content--><select style="display: none;"><!--content-->Yes, you could do that, but then there is no way to select a value (unless a default is set). Also, you can only have one value selected from the list at one time.<!--content-->Thanx,<br />
<br />
The <select style="display: none;"> works great.<br />
<br />
I don't want any user interaction with this object as it<br />
is used to only retain the initial CGI values placed into<br />
a Java String array using req.getParmaterValues. <br />
Consequently I needed an object to store multiple values<br />
with the same object name when the form is submitted<br />
(or, better said, re-submitted to itself).<br />
<br />
All values placed into the array are "selected" so they<br />
get passed on each subsequent submit.<!--content-->But, like I said before, a select list can only have one value selected at a time. Only the selected value is passed to your script, so what you're saying doesn't make any sense. You should use the <input type="hidden"...> method, which is automatically hidden, and is intended for this type of use. Also, I don't believe it's possible to have a form with multiple inputs of the same name. I'm pretty sure it would overwrite all of the other inputs with the one that comes last in the source when it is submitted. You're best bet is to use either one hidden input with all of the values, which can be split into an array or individual variables, or to use multiple hidden inputs.<!--content-->Oh, wait, are you writing in new options in the select list after each submit? How would those values get passed to your processing script?<!--content-->At home now (not at work) so please forgive any servlet<br />
syntax errors. Here's a snippet that should answer your<br />
last question...<br />
<br />
<br />
out.println("<select name=\"arg\" style=\"display: none;\" multiple>");<br />
for (int i=0;i<myArray.length;i++) {<br />
out.println("<option value=\"" + myArray[0] + "\" selected></option>");<br />
}<br />
out.println("</select>");<br />
<br />
<br />
For every item captured by "req.getParameterValues", a<br />
"selected" option will be created and, consequently, passed<br />
for each new form submit.<br />
<br />
Since, however, it is not visible (thanx again to fredmv<br />
for the non-visible HTML), these values will always be<br />
present and unchangeable by the user.<br />
<br />
I gotta check this stuff with prehistoric browsers, such as<br />
Netscape 4.7x, to make sure the function is consistent.<!--content-->Sorry - syntax error on the "options" line inside the<br />
iteration. It should read...<br />
<br />
<br />
for (int i=0;i<myArray.length;i++) {<br />
out.println("<option value=\"" + myArray + "\" selected></option>");<br />
}<br />
<br />
<br />
"myArray" is a simple string array. <br />
<br />
Note that all options are "selected" and, YES, select objects<br />
can be single or multi-selection objects, as indicated with<br />
the "multiple" attribute on the "<select>" tag.<!--content-->Oh, sorry, didn't know that. If it works, it works, though it's probably not the best solution...<!--content-->
 
Back
Top