pisze sobie skrypt który wyświetla losowy obrazek
cała strona wygląda tak
Kod
<html>
<head>
<title> Losowy obrazek </title>
<script type="text/javascript">
var images = new Array();
<?php
$dir = 'img/';
$array = Array();
if($dh = opendir($dir))
{
$i=0;
while(($pozycja = readdir($dh)) != FALSE)
if(!is_dir($pozycja))
{
echo "images[$i] = $pozycja;\n ";
$array[$i++] = $pozycja;
}
closedir($dh);
}
echo "\n";
?>
function other()
{
document.getElementById("img").setAttribute("src", images[Math.floor(Math.random()*images.length)]);
}
</script>
</head>
<body>
<input type="button" onClick="other();" value="Losuj inny" />
<br /><br />
<?php echo '<img src="'.$dir.$array[rand(0, sizeof($array))].'" id="img" />' ?>
</body>
</html>
<head>
<title> Losowy obrazek </title>
<script type="text/javascript">
var images = new Array();
<?php
$dir = 'img/';
$array = Array();
if($dh = opendir($dir))
{
$i=0;
while(($pozycja = readdir($dh)) != FALSE)
if(!is_dir($pozycja))
{
echo "images[$i] = $pozycja;\n ";
$array[$i++] = $pozycja;
}
closedir($dh);
}
echo "\n";
?>
function other()
{
document.getElementById("img").setAttribute("src", images[Math.floor(Math.random()*images.length)]);
}
</script>
</head>
<body>
<input type="button" onClick="other();" value="Losuj inny" />
<br /><br />
<?php echo '<img src="'.$dir.$array[rand(0, sizeof($array))].'" id="img" />' ?>
</body>
</html>
i chodzi o to że nie wywołuje mi tej funkcji other po kliknięciu w button'a
w firebug'u po kliknięciu występuje błąd other is not defined
co zrobić żeby jak to mój nauczyciel mówi fungowało
