Moynul
Moynul

Reputation: 635

Random Images not displaying images

                <script language="javascript" type="text/javascript">
                     <!--
                        document.write("<img src =../images/"" + Math.floor( 1 + Math.random() * 3) + ".jpg\" />");
                        <img src="../images/1.jpg" width="500" height="281" alt=""/>
                     // -->
                 </script>

Hey guys, as you can see that the second line in the script code shows where the source of the images are.

I am trying to obtain an image at random and write it.

But it's showing the icon of the image (the small icon which indicates the image hasn't loaded.

Can someone please show me how the coding will go. Thank you.

I'm new to javascript, so sorry for being a "newbie".

Upvotes: 0

Views: 82

Answers (1)

Justus Romijn
Justus Romijn

Reputation: 16019

In javascript, you can escape quotes by putting a backslash in front of it. Also, you should not use spaces between your attribute keys and values.

<script language="javascript" type="text/javascript">
<!--
document.write("<img src=\"../images/" + Math.floor( 1 + Math.random() * 3) + ".jpg\" />");
// -->
</script>

Upvotes: 1

Related Questions