I'm not sure, but I think he meant he wanted both (1) a <select> list based
on elements in a database and (2) a <textarea> element where the client
would enter something that does not appear in the <select> list.

If so, you could use a script that uses the records in your database and
has a final <option> for "Other".  For instance, on a MySQL database:

<?php

if (isset ($submit)) {
    if (isset ($other_color)) {
        $q_ins1 = "INSERT INTO colors VALUES ('$other_color')";
        $q_ins2 = @mysql_query ($q_ins1);
    } else {
        $q_ins3 = "INSERT INTO colors VALUES ('$color_choice')";
        $q_ins4 = @mysql_query ($q_ins3);
    }
}

?>

<html>
<head></head>
<body>
<form action="<?=$PHP_SELF ?>" method="post">
<select name="color_choice">

<?php

$q1 = "SELECT color FROM colortable";
$q2 = @mysql_query ($q1);

/* Prints out the drop-down menu of colors (blue, green, red, yellow) */
while ($q3 = @mysql_fetch_array ($q2)) {
    echo "<option value=\"$q3[color]\">$q3[color]</option>";
}

?>
<option value="other">Other</option>
</select>
<textarea name="other_color" cols="50" rows="2"></textarea>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>

You'd want to change the form according to your needs, and you may think of
a better way of doing it.  But, that might give you an idea of how to go
about your project, assuming that I understood what you meant.


> [Original Message]
> From: Jason Wong <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Date: 07/08/2004 8:00:38 PM
> Subject: Re: [PHP] onchange drop down list and text field
>
> On Friday 09 July 2004 10:41, Curlys wrote:
>
> >  I would like to ask another help from u all ,
> > I have an data submitable form . There is some fields. It is connected
with
> > mysql database. so I want to put to these fields as drop down list as
well
> > as text input area. say , if when i adding data , if it is in the
database
> > there should be possibility to select from the drop down list . and if
it
> > is not there data should allow to enter . can u all help me on this
matter
> > ?
>
> What exactly is the problem you're having? Assuming you know how to pull
the 
> data out of the DB then it's simply a matter of wrapping <select> and 
> <option> tags around them.
>
> -- 
> Jason Wong -> Gremlins Associates -> www.gremlins.biz
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
> ------------------------------------------
> Search the list archives before you post
> http://marc.theaimsgroup.com/?l=php-general
> ------------------------------------------
> /*
> Try the Moo Shu Pork.  It is especially good today.
> */
>
> -- 
> 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

Reply via email to