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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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']
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.