Forum Moderators: coopster
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>";
?>
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.
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.
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'];
?>
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.