0

The script file and the jsfile reside together on an Apache homepage server. In the head section of index.html we have

 <script type="text/javascript" src="someurl/jsfile.js"></script/>

And in the scriptfile we refer to jsfile by

function init_disp() {array_len = jsfile.length...

Running the scriptfile with or without someurl produces an "'jsfile' is undefined" error. Is there a problem here, or if the server software is blocking the script, does it do it by nulling the variables?

Using IE11 with enhance protect and 64 bit enhance protect, 64 bit Java. Edit: The entire scriptfile (not my own) is this:

    addEvent(window,"load",init_disp);
    addEvent(document,"click",show_init);
    // function to add an event listener
    function addEvent(o,e,f) {
    if (o.addEventListener) {
    o.addEventListener(e,f,false);
    return true;
    }
    else if (o.attachEvent) {
    return o.attachEvent("on"+e,f);
    }
    else {
    return false;
    }
    }
    // integer "random()"
    function rand (n)
    {
    return (Math.floor( Math.random ()*n));
    }
    // BEGIN customization settings
    var char_pause = 60; // pause on each character, milliseconds
    var quote_pause = 8000; // pause to show complete quote, milliseconds
    // END customization settings
    var quoteindex;
    var quote,attribution;
    var pos;
    var box;
    var array_len;
    var quote_len,attrib_len;
    var interval = null;
    var busy;
    var cursor_span = "<span class=\"quotefont quotecursor\">";
    var hide_span = "<span class=\"quotefont hidecolor\">"
    var attr_div = "<p></p><div class=\"quotefont attrib\">";

    function init_disp() {
    array_len = jsfile.length;
    box = document.getElementById("quotebox");
    quoteindex = rand(array_len);
    show_init();
    }
    function show_init() {
    busy = false;
    clearInterval(interval);
    quote_array = jsfile[quoteindex].split("\t");
    quote = quote_array[0];
    attribution = quote_array[1];
    quote_len = quote.length;
    attrib_len = attribution.length;
    quoteindex = (quoteindex+1) % array_len;
    pos = 0;
    interval = setInterval('show_quote()',char_pause);
    }
    function show_quote() {
    pos++;
    if(!busy) {
    busy = true;
    if(pos <= quote_len) {
      box.innerHTML = quote.substring(0,pos) +
      cursor_span +
      quote.substring(pos,pos+1) +
      "</span>" +
      hide_span +
      quote.substring(pos+1) +
      "</span>";
    }
    busy = false;
    }
    if(pos > quote_len) {
    pos = 0;
    clearInterval(interval);
    interval = setInterval('show_attr()',char_pause);
    }
    }
    function show_attr() {
    pos++;
    if(!busy) {
    busy = true;
    if(pos <= attrib_len) {
      var attr = attribution.substring(0,pos);
      box.innerHTML = quote + attr_div + attr + "</div>";
    }
    busy = false;
    }
    if(pos > attrib_len) {
    clearInterval(interval);
    interval = setInterval('show_init()',quote_pause);
    }
    }
2
  • 1
    This is javascript, not java. Commented Aug 10, 2015 at 14:56
  • I'm voting to close this question as off-topic because it works as expected; or rather, that's not how that works. Commented Aug 10, 2015 at 15:08

1 Answer 1

3

When you load a Javascript file using <script> tag, that file gets executed, not loaded as a Javascript object.

Sign up to request clarification or add additional context in comments.

11 Comments

Yes, any luck with the undefined?
As per my answer, the result of <script> execution is not being set into jsfile variable, so it is undefined.
You just saw it? I can redo the question with his code if you like.
On that page I can only see some html code that executes JS files, no inline Javascript code. Anyway, if he is counting lines, I guess he is counting lines in a text area, not in a js file.
quotes.js initialiazes a global quotes variable that persists on the page.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.