SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Whats wrong with this?

    <script type="text/JavaScript" src="here.js">
    <!--
    function output() {
    var i = Math.round(5*Math.random());
    document.write(safetyTips[i]);
    }
    output();
    //-->
    </script>
    safetyTips[] - this array is in here.js ...

  2. #2
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Random ouputs a number between 0 and 1. You'll have to multiply it times 10 to be sure you have an integer, not a fraction, as a result.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    When you link to a .js file, the linked file acts as if it was put between the <script> and </script> tags. In IE and FF1.0, the src file will overwrite anything listed between the <script> tags.

    To solve your problem, link to the file in one set of script tags, and then follow that with another set of <script> tags with the lines of code you posted.


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
  •