SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Script Value

  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2012
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Script Value

    Hello

    I want do appear text in div with class name "example"..i try two methods but.. with this method don't work i don't know why, but with the method below works. (I'm going get the file .js correctly.)
    Anyone knows the problem?

    Code:
    <html>
    <head>
    <script type="text/javascript" src="/js/phases.js"></script>
    </head>
    <body>
    <div class="example"><script>document.write(mensage[rand]);</script></div>
    </body>
    </html>
    Code:
    <html>
    <head>
    <script type="text/javascript">
       var mensage = new Array(
       'example',
       'example2',
       var rand = Math.floor(Math.random() * 2);
    </script>
    </head>
    <body>
    <div class="example"><script>document.write(mensage[rand]);</script></div>
    </body>
    </html>
    Thanks!

  2. #2
    SitePoint Zealot moretea's Avatar
    Join Date
    Jun 2004
    Location
    Texas, USA
    Posts
    118
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    In the second example, you need to close the mensaje Array after element2.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,608
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Why are you writing JavaScript for Netscape 4 and earlier browsers. The document.write statement should not be used for more modern browsers such as Internet Explorer Five.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •