Snafu: php array mit javascript nutzen

Beitrag lesen

Schau mal, hier ist ein Beispiel:

  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<title>Foobar</title>  
<script type="text/javascript">  
// das folgende array musst du von der php datei mit echo / print erzeugen.  
// oder du machst es mit ajax und json  
foo = new Array(  
 new Array("Heute", "ist", "Dienstag!"),  
 new Array("Morgen", "ist", "Mittwoch!"),  
 new Array("Gestern", "war", "Montag!"),  
 new Array("Meine", "Katze", "schläft!")  
);  
  
function change(key) {  
 document.getElementById('elem0').value = foo[key][0];  
 document.getElementById('elem1').value = foo[key][1];  
 document.getElementById('elem2').value = foo[key][2];  
}  
</script>  
</head>  
<body>  
<select name="foo" onchange="change(this.options[selectedIndex].value)">  
 <option value="0">Nummer 1</option>  
 <option value="1">Nummer 2</option>  
 <option value="2">Nummer 3</option>  
 <option value="3">Nummer 4</option>  
</select>  
<br />  
<input id="elem0" type="text" />  
<input id="elem1" type="text" />  
<input id="elem2" type="text" />  
</body>  
</html>  

--
LG,
Snafu