bon2310 Posted July 13, 2012 Share Posted July 13, 2012 Hi, Can anyone help I am trying to add an option to a drop down list that allows the user to add a new item to the list. the code I have so far is - //create select options to pick sub-list $select = '<option value="">Select an option</option>'; $stmt = $mysqli->prepare("SELECT id, type FROM table1"); $stmt->execute(); $stmt->bind_result($id, $type); while ($stmt->fetch()) { $select .= "<option value='" . $id . "'"; if ($input['group'] == $id) { $select .= "selected='selected'"; } $select .= ">" . $type . "</option>"; } //create main options $group = input['type'] $sel = '<option value="">Select an option</option>'; $stmt = $mysqli->prepare("SELECT id, type FROM table2 WHERE 'table2.group' = $group"); $stmt->execute(); $stmt->bind_result($id, $type); while ($stmt->fetch()) { $sel .= "<option value='" . $id . "'"; if ($input['group'] == $id) { $select .= "selected='selected'"; } $sel .= ">" . $type . "</option>"; } $sel .= '<option value="">Add a new item</option>'; the code in the form is - <label for="type">Name: *</label> <select name="type"> <?php echo $sel; ?> </select> How can i get to allow the user to "on selecting the 'Add a new item' option to input a new item. Help please Brian Quote Link to comment https://forums.phpfreaks.com/topic/265611-option-to-add-new-item-to-drop-down-list/ Share on other sites More sharing options...
cyberRobot Posted July 13, 2012 Share Posted July 13, 2012 I'm assuming that you want the option to be added without reloading the page. If so, you'll need to use something like JavaScript. Is this what you're looking for? http://forums.phpfreaks.com/index.php?topic=338474.0 Quote Link to comment https://forums.phpfreaks.com/topic/265611-option-to-add-new-item-to-drop-down-list/#findComment-1361276 Share on other sites More sharing options...
bon2310 Posted July 13, 2012 Author Share Posted July 13, 2012 Thanks that did it. I was trying to do it just in PHP but this will take care of that issue. Being that I am only starting with PHP I am sure I will be back Quote Link to comment https://forums.phpfreaks.com/topic/265611-option-to-add-new-item-to-drop-down-list/#findComment-1361310 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.