/    Sign up×
Community /Pin to ProfileBookmark

Non-displayed "Select" list

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…

to post a comment
HTML

11 Comments(s)

Copy linkTweet thisAlerts:
@PunkSktBrdr01Oct 31.2003 — If you don't want a form input to be shown, use <input type="hidden"...
Copy linkTweet thisAlerts:
@oleragauthorOct 31.2003 — 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.
Copy linkTweet thisAlerts:
@PunkSktBrdr01Oct 31.2003 — 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()).
Copy linkTweet thisAlerts:
@fredmvOct 31.2003 — &lt;select style="display: none;"&gt;
Copy linkTweet thisAlerts:
@PunkSktBrdr01Oct 31.2003 — 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.
Copy linkTweet thisAlerts:
@oleragauthorOct 31.2003 — 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.
Copy linkTweet thisAlerts:
@PunkSktBrdr01Oct 31.2003 — 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.
Copy linkTweet thisAlerts:
@PunkSktBrdr01Oct 31.2003 — 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?
Copy linkTweet thisAlerts:
@oleragauthorNov 01.2003 — At home now (not at work) so please forgive any servlet

syntax errors. Here's a snippet that should answer your

last question...

[code=php]
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>");
[/code]


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 [B]fredmv[/B]

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.
Copy linkTweet thisAlerts:
@oleragauthorNov 01.2003 — Sorry - syntax error on the "options" line inside the

iteration. It should read...

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


"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.
Copy linkTweet thisAlerts:
@PunkSktBrdr01Nov 01.2003 — Oh, sorry, didn't know that. If it works, it works, though it's probably not the best solution...
×

Success!

Help @olerag spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...