Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2009
    Location
    Farnborough, Hampshire UK
    Posts
    3
    Rep Power
    0

    Default Using Script src with a variable file name

    Hello all. I am almost completely new to web design and use FrontPage to create pages. I am, therefore, also almost completely new to working with java and tend to jazz up web pages by taking advantage of code that people make available on web sites.

    I am currently trying to use the Script src tag as follows:

    <script language=JavaScript1.2 src='MyScript.js'></script>

    However, I am trying to write it so that I have a variable for the src parameter. This is so that when I change the name of the script file, the src will still point to the correct "new" file. The resaon I need this is that using a new file name would "force" my user's browsers to pick up the new file without having to clear the cache.

    Further up in the code I have written this:

    <script language=JavaScript>
    var today = new Date()
    var myyear = today.getFullYear()*10000
    var mymonth = (today.getMonth()+1)*100
    var myday = today.getDay()+1
    var Mydate = myyear+mymonth+myday
    var MyLoader = MyScript" + Mydate + ".js"

    which, I beleive, creates a variable called MyLoader with the value:

    MyScriptyyyymmdd.js

    where yyyymmdd is today's date.

    Then simply by renaming my script file to MyScript20090303.js for example, this is the file that should be accessed.

    However, when I replace by calling line with

    <script language=JavaScript1.2 src=MyLoader></script>

    I get an error and the script file does not get run.

    Is there a way round this or have I missed something out to tell the script command that MyLoader is a variable?

    Many thanks for any help I receive!


    Sidders

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Well, Java is a programming language, and Javascript is a scripting language used in Web browsers. They have two things in common:

    1. They both have Java in the name.
    2. They both look like C code.

    Other than that, they are completely different. You might try asking your question on a Javascript forum. Good luck!

  3. #3
    Join Date
    Mar 2009
    Location
    Farnborough, Hampshire UK
    Posts
    3
    Rep Power
    0

    Default

    Steve - Thanks for the reply. I am slowly learning the difference between the two! However, on this occasion (and I am willing to be corrected) my understanding is that the .js file I am calling is ok. In this case it is the reference to that file that I am trying to get to work correctly and this is in Java code rather than JavaScript or is my understanding of the differences not as advance as I thought?

  4. #4
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    the difference between java and javascript is that they are not related. period. the extension "js" stands for javascript. not java.

  5. #5
    Join Date
    Mar 2009
    Location
    Farnborough, Hampshire UK
    Posts
    3
    Rep Power
    0

    Default

    OK. Does this mean that the coding I have shown which is in an html file is still classed as "Java Script" rahter than Java even though it is not in a .js file?

  6. #6
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    everything you are doing, i can guarantee is javascript.

  7. #7
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

Similar Threads

  1. How build the applicatoin by using Batch file script
    By Kishore.Kumar in forum Eclipse
    Replies: 0
    Last Post: 02-11-2009, 08:42 AM
  2. Problem creating a Post script file
    By krishnan.1000 in forum New To Java
    Replies: 0
    Last Post: 02-14-2008, 07:15 PM
  3. variable access from another file
    By riadmazloum in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 07:13 PM
  4. building file and variable names from variables
    By madad2005 in forum New To Java
    Replies: 2
    Last Post: 07-18-2007, 04:47 PM

Posting Permissions

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