How to input/add a new option in a dropdown list

How to input/add a new option in a dropdown list

by Ishraga Allam -
Number of replies: 3

Hi and Good day to you.

How can a create a dropdown list with an option to add a dynamic option to it.

If I want a static dropdown list in html I do as:

<select name="cars">

<option value="volvo">Volvo</option>

<option value="saab">Saab</option>

<option value="fiat" selected="selected">Fiat</option>

<option value="audi">Audi</option>

</select>

 

If I want a file options I do as:

<?php

$con = mysql_connect("localhost","root","");

mysql_select_db("Stock1", $con);

$result3=mysql_query("SELECT item FROM item", $con);

if($result3) {

?>

<form id="form1" name="form1" method="post" action="welcome.php">

<select name="name" id="name">

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

<?php

while($rows=mysql_fetch_assoc($result3)) {?>

<option value="<?php echo $rows['item']?>" selected="name"><?php echo $rows['item'] ?></option>

<?php

}

 

mysql_free_result($result3);?>

</select>

<input type="submit" name="submit" value="تسليم"/>

</form>

<?php

}

else die("SQL failed.".$sql);

?>

I want to have an input option to be inserted into the select statement. How can I do that, please help me…

Average of ratings: -
In reply to Ishraga Allam

Re: How to input/add a new option in a dropdown list

by Stephen Mc Guinness -

Hi Ishraga,

I think the control you are looking for is called a 'combo' box in some development libraries, but there is no such control in HTML.

Usually this is created in HTML using a combination of the select element and a standard text input element.

You can see examples of how it can be achieved here: http://www.cs.tut.fi/~jkorpela/forms/combo.html

Stephen Mc Guinness
Enovation Solutions