Click to See Complete Forum and Search --> : Non-displayed "Select" list


olerag
10-30-2003, 04:56 PM
I want to create/populate a multi-selection Select list
and have all of the options "selected". Help here is not
necessary.

However, I do not want this "form object" to be displayed
but only registered when the form is "submitted".

Is this possible? If so, what would I need to do in either
HTML or Javascript.

Thanx...

PunkSktBrdr01
10-30-2003, 06:58 PM
If you don't want a form input to be shown, use <input type="hidden"...

olerag
10-30-2003, 07:36 PM
When passed, a "hidden" object would only permit one
value, I believe, to be assigned to the object, such as:
myServlet?arg=value1

I would need to account for multiple values of the same
object name during a submit, (such as "arg", as used here):
myServlet?arg=value1&arg=value2&arg=value3

Hence my usage of a non-displayed "select" object.

This is my reasoning for using this particular object
however I don't want to display it as I will be
formulating the object programmatically.

PunkSktBrdr01
10-30-2003, 08:18 PM
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()).

fredmv
10-30-2003, 08:29 PM
<select style="display: none;">

PunkSktBrdr01
10-30-2003, 08:33 PM
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.

olerag
10-31-2003, 08:03 AM
Thanx,

The <select style="display: none;"> works great.

I don't want any user interaction with this object as it
is used to only retain the initial CGI values placed into
a Java String array using req.getParmaterValues.
Consequently I needed an object to store multiple values
with the same object name when the form is submitted
(or, better said, re-submitted to itself).

All values placed into the array are "selected" so they
get passed on each subsequent submit.

PunkSktBrdr01
10-31-2003, 03:45 PM
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.

PunkSktBrdr01
10-31-2003, 03:48 PM
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?

olerag
10-31-2003, 07:52 PM
At home now (not at work) so please forgive any servlet
syntax errors. Here's a snippet that should answer your
last question...


out.println("<select name=\"arg\" style=\"display: none;\" multiple>");
for (int i=0;i<myArray.length;i++) {
out.println("<option value=\"" + myArray[i][0] + "\" selected></option>");
}
out.println("</select>");


For every item captured by "req.getParameterValues", a
"selected" option will be created and, consequently, passed
for each new form submit.

Since, however, it is not visible (thanx again to fredmv
for the non-visible HTML), these values will always be
present and unchangeable by the user.

I gotta check this stuff with prehistoric browsers, such as
Netscape 4.7x, to make sure the function is consistent.

olerag
10-31-2003, 08:06 PM
Sorry - syntax error on the "options" line inside the
iteration. It should read...


for (int i=0;i<myArray.length;i++) {
out.println("<option value=\"" + myArray[i] + "\" selected></option>");
}


"myArray" is a simple string array.

Note that all options are "selected" and, YES, select objects
can be single or multi-selection objects, as indicated with
the "multiple" attribute on the "<select>" tag.

PunkSktBrdr01
10-31-2003, 09:21 PM
Oh, sorry, didn't know that. If it works, it works, though it's probably not the best solution...