Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> bardzo prosty skrypt losowania obrazka, małe połączenie JS i PHP
cybertix
post
Post #1





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 28.08.2007

Ostrzeżenie: (0%)
-----


Witam

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>



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 (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif) , żeby ta funkcja była 'widoczna' ?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 7.10.2025 - 14:34