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>
functiononCambioDeOpcion(combobox){
alert("Seleccionaste:"+combobox[combobox.selectedIndex].text+
"\nSuvalores:"+combobox.value);
}
</script>
</header>
<body>
<selectclass="select_autor"name="autor"
onchange="onCambioDeOpcion(this)">
<optionselected="selected">Seleccionefabricante</option>
<?php
for($i=0;$i<count($data);$i++)
{
?>
<optionvalue="<?phpecho$data[$i]->valor?>">
<?phpecho$data[$i]->titulo?></option>
<?php
}
?>
</select>
</body>
</html>
希望本文所述对大家的php程序设计有所帮助。