Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple JS Question

    I have begun renovation of an old website of mine, and I would like some help. I hope to include a "random quote" bar to the side of each page. No problem. I have coded the array and random number and display properties, and everything works fine.

    However, as I have it now, the quote array (about 30 quotes so far) is included in the code for each page I wish to include the random quote bar on. This works, but of course makes adding new quotes difficult since I have to go through each page and put them in again and again. I do know Java, but I have very little experience with JS, and I was wondering what JS syntax would give me the ability to access my large quote array from a single file, which I could easily add to seperately. This would allow me to add a quote to this seperate file and as a result each page with the "random quote" function would be able to retrieve the new quotes from that file.

    Can JS do this?

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Sure, just make your script into an external file.

    Code:
    <SCRIPT type="text/javscript" SRC="http://www.mypage.com/myscript.js"></SCRIPT>
    Make sure that your external script doesn't have the script tag in it and save it with the .js extension.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what he says, use virtual paths instead of absolute one though.

  • #4
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    perfect. that makes things much easier.

    thanks for the help fellas.

  • #5
    New Coder
    Join Date
    Jan 2004
    Location
    South Midlands
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Helped me too!

    Thanks for this thread - I'm not as clear on JS as I should be, and I didn't know how to make a script external !
    And is our future wounded by Philosophies our daddies had?
    - - Alisha's Attic - -

  • #6
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    If you are just starting off in javascript, head over to w3schools.com and check out their tutorial.


  •  

    Posting Permissions

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