lucy Posted August 27, 2009 Share Posted August 27, 2009 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 Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 27, 2009 Share Posted August 27, 2009 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. Quote Link to comment Share on other sites More sharing options...
lucy Posted August 27, 2009 Author Share Posted August 27, 2009 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 Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 27, 2009 Share Posted August 27, 2009 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'] } Quote Link to comment Share on other sites More sharing options...
lucy Posted August 27, 2009 Author Share Posted August 27, 2009 Thanks, that works perfectly!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.