Jump to content

[SOLVED] override input from combo box with text field


lucy

Recommended Posts

I wasnt sure weather to put this in PHP Coding Help or the MYSQL board.

 

I have a combo box which automatically generates the items within it, from a mysql databse field.

 

Most of the time i will be selecting one of the fields from the combo box, but sometimes i may not, i may want to enter into the database, data which is not in the combo box.

 

How can i do this?

 

I was thinking having a check box, and if it is selected, use the text which is in a text box instead of the value from the combo box, but i dont know how i would go about implementing it.

 

Any ideas or suggestions would be most appreciated!

 

Thanks,

Lucy

it would probably be easiest to simply put a text input below the select list. then, when you're processing the form, if the text box is NOT empty, use its value instead of the selected item. this would work on the assumption that the only reason anyone would enter anything into the text input is if they don't want to select one.

Yeah that sounds obvious, i dont know how i didnt think of that!

 

I dont know how i would go about implementing this as the combo box automatically populates itself in a way, so the most occuring data in a certain field is put at the top of the combo box and selected, so the combo box is set from when the page loads.

 

How could i enballe the text input to override this?

 

Thanks,

Lucy

simply place the text input below the select box, and then when you're processing the form, check if the text input is empty first:

 

<select name="selected_data">
<!-- blah -->
</select>

<input type="text" name="override_selected_data" />

 

then, when processing the form:

 

if (!empty($_POST['override_selected_data']))
{
  // use the value entered into $_POST['override_selected_data']
}
else
{
  // use the value selected in $_POST['selected_data']
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.