Home > Programming, php > php: Dynamically fill a select box

php: Dynamically fill a select box

December 30th, 2005 ^Lestat Leave a comment Go to comments

One way to fill a select box with array elements.

<html>
<head>
<title>Select Box</title>
</head>
<body>

< ?php
$myArray = array('cat' , 'dog' , 'mouse' , 'cow');
?>

<select name="myselect">
<option value=""></option> // Sets blank entry *optional*
< ?php
foreach($myArray as $value){ // Loop through each element
  print("<option value=\"$value\">$value<option>");
}
?>
</option></select>

</body>
</html>

php, select, drop down

Categories: Programming, php Tags:
  1. May 20th, 2008 at 14:16 | #1

    Thanks, I was having trouble with this.

  2. February 15th, 2011 at 03:07 | #2

    This is a very good site.

  3. December 16th, 2011 at 20:58 | #3

    Well I really enjoyed reading it. This post offered by you is very helpful for correct planning.

  4. January 11th, 2012 at 04:45 | #4

    prodigious post you’ve own

  5. March 5th, 2012 at 03:26 | #5

    Of course, what a great site and advisory posts, Can I add backlink – import your rss feed? Regards, Reader.
    [url=http://www.shop-soccer-jerseys.com/]Cheap FootBall Shirts[/url]

  6. April 11th, 2012 at 01:32 | #6

    I just read through the entire article of yours and it was quite good. This is a great article this informative information. I will visit your blog regularly for some latest post.

  1. No trackbacks yet.