This topic is locked

Default value in Combobox

6/17/2011 7:27:59 AM
PHPRunner General questions
U
unsearcheable author

Hello, i have a combobox of "field_id" that displays "field_name", and that defauld record as "John Doe", but this name isn't in table, if user don't choose any name from combo, assumes "John Doe".

As my understanding i have two problems:

Having the dropdown dependent from another and not having the record inserted in table...

How can i accomplish this ?
Regards.

U
unsearcheable author 6/19/2011

Does anyone know how to solve this ?
Regards.

C
cgphp 6/19/2011

If user doesn't select a value (the combo is set to Select) the combo POST var is set to empty string

<select name="your_combo">

<option value="">Select</option>

<option value="1">name_1</option>

<option value="2">name_2</option>

..

..

<option value="n">name_n</option>

</select>


Server side validation:



if($_POST['your_combo'] == "")

echo "John Doe";

else

echo $_POST['your_combo'];


Cheers

CGphp