Jump to content

option to add new item to drop down list


bon2310

Recommended Posts

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

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.