Form <select> field problem
| From: | Keiran Wynyard | Date: | Mon, 08 Jul 2002 09:22:16 +0000 |
| Subject: | Form <select> field problem | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-20387@lists.php.net to get a copy of this message | ||
Hi
I may be posting this to the wrong place, and if so I apologise. If someone knows of a
better place to post my query please tell me, and I will. :)
This problem is about 50% PHP and 50% Javascript, really to do with how the two interface
with each other.
Anyhoo, down to the problem.
I have a Select form item with 'multiple' set. It sends an array of values to be dissected
and applied to database tables, hence it's name value is 'groupchoice[]'. This all
works
well and good when some value(s) are selected, but obviously gives an error if the form is
sent with no value selected. What I need to do is come up with an elegant way of stopping
the form if no entries have been selected (or indeed if all entries have been deselected).
I have successfully used a Javascript function to do this, but it only works if the field
is named 'groupchoice'. The part of the function that is causing the problem is listed
below:
if (!document.existing.groupchoice.selectedIndex != "") //this works
if (!document.existing.groupchoice[].selectedIndex != "") //this gives a syntax error
Obviously if I call the field 'groupchoice' the information sent is no longer an array,
and therefore I cannot have multiple selections, which is imperative. I have thought of
other ways of doing the job, such as having an alert pop-up if there is an error and then
return them to the form, as opposed to before the form is sent, but didn't feel that this
was very elegant.
Have any of you PHP gurus out there experienced this kind of problem and found a solution?
I would be greatly appreciative if someone would share their expertise.
TIA
Keiran
keiran@wynyard.net