当前位置:首页 > PHP教程 > PHP高级教程

php使用数组填充下拉列表框的方法

本文实例讲述了php使用数组填充下拉列表框的方法。分享给大家供大家参考。具体实现方法如下:

<?php
$data = array(
  (object)array("titulo"=>"ford", "valor"=>"opcion1"),
  (object)array("titulo"=>"peugeot", "valor"=>"opcion2"),
  (object)array("titulo"=>"chevrolet", "valor"=>"opcion3"),
  (object)array("titulo"=>"volskwagen", "valor"=>"opcion4"),
);
?>
<html>
<header>
<script>
function oncambiodeopcion(combobox) {
  alert("seleccionaste: " + combobox[combobox.selectedindex].text +
   " nsu valor es: " + combobox.value);
}
</script>
</header>
<body>
<select class="select_autor" name="autor" 
onchange="oncambiodeopcion(this)" >
<option selected="selected">seleccione fabricante</option>
<?php
for($i=0; $i<count($data); $i++)
{
?>
  <option value="<?php echo $data[$i]->valor ?>">
  <?php echo $data[$i]->titulo ?></option>
<?php
}
?>
</select>
</body>
</html>

希望本文所述对大家的php程序设计有所帮助。


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!