RE: [PHP] how to create multiple selects within php
| From: | bruce | Date: | Mon, 18 Oct 2004 16:57:34 +0000 |
| Subject: | RE: [PHP] how to create multiple selects within php | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-199741@lists.php.net to get a copy of this message | ||
i've decided to punt...
and do something similar to what i had initially created, which implements
basically what you have below... the user will just have to be satisfied
with seeing the 1st item that's a default/dummy item...
thanks...
-bruce
-----Original Message-----
From: Silvio Porcellana [mailto:sporc@tin.it]
Sent: Monday, October 18, 2004 7:44 AM
To: php-general@lists.php.net
Subject: Re: [PHP] how to create multiple selects within php
You can do something like this:
<HTML>
<select name='foo'>
<option value=''> - - choose one - -</option>
<option value='1'>fff</option>
<option value='2'>aaa</option>
.....
</select>
</HTML>
and then in your PHP:
<?php
if ($_POST['foo'] != '') {
# do something
} else {
# Ops, user didn't choose a valure from the 'foo' select!!!
}
?>
Anyway, you can catch this only *after* the form is submitted: in case you
want to block
the user from submitting the form if the 'foo' select is empty you need to
use some
javascript:
<script language="JavaScript">
function check_form(form) {
if (form.foo.value == '') {
alert("C'mon!!!");
return false;
}
}
</script>
and in your HTML you need to add something like this to the <form> tag:
<HTML>
<form action="pippo.php" method="post" onSubmit="return
check_form(this);">
<select ...>
....
</select>
</form>
</HTML>
Anyway, this has more to do with HTML and JavaScript than PHP...
HTH, cheers
Silvio Porcellana
bruce wrote:
> ok...
>
> it appears to be a case of user err.. the spec seems to state that if the
> user doesn't select/specify an item, the select should return the 1st item
> within the list... arrrgggh!! this is what's happening...
>
> so my question is still, how can i implement some logic that requires the
> user to actually select an item? or, how can i detect when a user has
> actually selected a list item??????
>
> thanks...
>
> -bruce
>
>
> -----Original Message-----
> From: bruce [mailto:bedouglas@earthlink.net]
> Sent: Monday, October 18, 2004 7:07 AM
> To: php-general@lists.php.net
> Subject: [PHP] how to create multiple selects within php
>
>
> hi...
>
> i can create a form with a single select by something like:
>
> <form>
> <select name='foo'>
> <option val='1'>fff</option>
> <option val='2'>aaa</option>
> </select>
> <input >
> </form>
>
> however, i need to know how to create a multiple menu/list within a single
> form.
>
> i've tried a few different approaches, but i'm doing something wrong, in
> that the querystring is being populated with a value for the select list
var
> even though i don't select the item.
>
> if someone can point me to an actual working example of php code that
> generates multiple lists/menus within a form, i'd appreciate it!!
>
> thanks
>
> -bruce
>
> ps. if needed, i can supply the actual test code i've used to create the
> condition i'm describing...
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php