Forum Moderators: coopster

Message Too Old, No Replies

drop down list, select other and text input box appears.

         

brodie_r

1:35 pm on Feb 23, 2006 (gmt 0)

10+ Year Member



Coop mate, you must love me by now ;) For one of my drop down lists i have Clients, and in their have the everyday clients that are used. I want to be still be able to add a report even if they are not in the client list. So would it be better to have say, a drop down list for client names, and then underneath a static text input box for other. Or an option in the drop down list called other, and when select it brings up a text input box underneath (java i would assume).

If i have a drop down list, and next to it just say "or Other: __________", when they enter this in, then the initially selected from the drop down list will conflict?. What i really need is if code for "If text in text input box other, then use that. If no text in their use current selection from drop down list".

What are your thoughts.

Again my current code for displaying the dropdown list is:

<?php
require_once ('mysql_connect.php');
$sql = mysql_query("SELECT * FROM client");
echo "<select name=client> ";
while ($row = mysql_fetch_array($sql))
{
$sub = $row["list"];
$sub_id = $row["list"];
echo "<option value=$sub_id>$sub</option>";
}
echo "</select>";
?>

coopster

5:38 pm on Feb 23, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Clarification?

It sounds like you are saying you want to have a pre-populated select box from which your user can select an option. However, that select box may not contain the option the user would like, which then be a new option. So, if the desired option is not available, what is the best way to handle the situation? A text box where the user would tell us the new option desired?

Does that sum it up? If so, then I guess that would be a decision you would have to make based on your desired setup. Yes, you could certainly have an option in the select box named "other" or "new" or whatever and then have some JavaScript that prompts them to enter the desired option into a text input field.

brodie_r

5:26 am on Feb 24, 2006 (gmt 0)

10+ Year Member



Would their be a way to do this without javascript?

The best way i think would be to have the populated drop down list, and next to it a permanent other text input box. And if something is entered in the other text input box, it uses that value, if not then it uses the value of the drop down list selection.

Steerpike

6:12 am on Feb 24, 2006 (gmt 0)

10+ Year Member



<?php
require_once ('mysql_connect.php');
$sql = mysql_query("SELECT * FROM client");
echo "<select name=client> ";
while ($row = mysql_fetch_array($sql))
{
$sub = $row["list"];
$sub_id = $row["list"];
echo "<option value=$sub_id>$sub</option>";
}
echo "</select>";

echo "Or other";
echo "<input type='text' name='client_text'>";
?>

The in the page you submit to have:

<?
$client = $_POST['client_text'];
if(!$client)
$client = $_POST['client'];
?>

Anyango

4:22 pm on Feb 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




The best way i think would be to have the populated drop down list, and next to it a permanent other text input box. And if something is entered in the other text input box, it uses that value, if not then it uses the value of the drop down list selection.

Perfect solution.

put a little message along with it too like "if item is not listed, please enter it here" this n that.

brodie_r

3:30 am on Feb 25, 2006 (gmt 0)

10+ Year Member



Yes, Steerpike's code was excellent, worked a dream. I think this way is better than going down the javascript track.