Código PHP:
<?php
$colors = array(
0 => "Negre",
1 => "Marró",
2 => "Vermell",
3 => "Carbassa",
4 => "Groc",
5 => "Verd",
6 => "Blau",
7 => "Violeta",
8 => "Gris",
9 => "Blanc");
function opcio1($szColorNombre, $szColor){
echo "<option selected='selected' value=\"$szColorNombre\">$szColor</option>\n";
}
?>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<title>Canvi d'un color d'un resistor bàsic</title>
</head>
<body>
<br>
<form method='POST' action='ex03f.php'>
<table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="2">
<tbody>
<tr>
<td>
<IMG SRC='imatges/resleft.png' WIDTH=127 HEIGHT=182 ALIGN=left HSPACE=0 BORDER=0>
<?php
$barColor = array("rBlack.png","rBrown.png","rRed.png","rOrange.png","rYellow.png",
"rGreen.png","rBlue.png","rViolet.png","rGray.png","rWhite.png");
print "<IMG SRC='imatges/".$barColor[$_REQUEST["tensSelect"]]."' NAME='tens' WIDTH=21 HEIGHT=182 ALIGN=left HSPACE=0 BORDER=0>";
?>
<IMG SRC='imatges/rBrown.png' NAME='ones' WIDTH=21 HEIGHT=182 ALIGN=left HSPACE=0 BORDER=0>
<IMG SRC='imatges/rRed.png' NAME='mult' WIDTH=21 HEIGHT=182 ALIGN=left HSPACE=0 BORDER=0>
<IMG SRC='imatges/spacer.png' WIDTH=17 HEIGHT=182 ALIGN=left HSPACE=0 BORDER=0>
<IMG SRC='imatges/rGold.png' NAME='tol' WIDTH=21 HEIGHT=182 ALIGN=left HSPACE=0 BORDER=0>
<IMG SRC='imatges/resright.png' WIDTH=127 HEIGHT=182 ALIGN=left HSPACE=0 BORDER=0>
</td>
</tr>
<tr>
<td>
<br>
<br>
<select name="tensSelect" onchange="submit()">
<?php
foreach($colors as $clave => $valor){
opcio1($clave, $valor);
}
?>
</select>
</td>
</tr>
</tbody>
</table>
</form>
<br>
<br>
</body>
</html>