Trying to reference external .js file - help please...

Discussion in 'JavaScript' started by freelancing, Jun 19, 2007.

  1. #1
    This has been driving me nuts for days with no luck. I had this script pasted directly on to the webpage and it worked fine, however the page would not validate because the validator was reading the javascript as html (4.01 strict) and popping up errors, so I wanted to make it an external .js file and link to it at a certain spot on the webpage. However, it does not appear on the webpage.

    In my <head>, I have:

    <script type="text/javascript" language="Javascript" src="/meaningsearch.js">
    </script>
    Code (markup):
    *I've tried using the full path as well, no luck.

    In the <body>, I have:
    <script type="text/javascript">
    makeMyMenu();
    </script>
    Code (markup):
    And the original external .js file is this:
    
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    
    function selectaplace(form) {
    
    var appname= navigator.appName;
    
    var appversion=parseInt(navigator.appVersion);
    
    if (appname == "Netscape" && appversion >= 3) {
    
    var formindex=form.bymeaningsearch.selectedIndex;
    
    var storage=form.bymeaningsearch.options[formindex].text;
    
    if (form.bymeaningsearch.options[formindex].value != "none") {
    
    var msg=storage+"You are now being transferred to the -> "+storage;
    
    for (var spot=0;spot<msg.length-storage.length;spot++) {
    
    var x=msg.substring(spot,msg.length);
    
    form.bymeaningsearch.options[formindex].text=x;
    
    for(var d=0;d<150;d++) { };
    
    }
    
    window.location=form.bymeaningsearch.options[formindex].value;
    
    form.bymeaningsearch[formindex].text=storage;
    
    } else  {
    
    form.bymeaningsearch[formindex].text="Not a real option!";
    
    for(var d=0;d<1250;d++) { };
    
    form.bymeaningsearch[formindex].text=storage;
    
       }
    
    }
    
    else {
    
    var formindex=form.bymeaningsearch.selectedIndex;
    
    window.location=form.bymeaningsearch.options[formindex].value;
    
       }
    
    }
    
    function makeMyMenu() {
    
    document.write ('<form><select name="bymeaningsearch" onChange="selectaplace(this.form)" size=1>');
    
    document.write ('<option value="">Select Meaning');
    
    document.write ('<option value="/SearchResults.asp?Search=attract">Invoke Attraction');
    
    document.write ('<option value="/SearchResults.asp?Search=beauty">Invoke Beauty');
    
    document.write ('<option value="/SearchResults.asp?Search=confidence">Invoke Confidence')
    
    document.write ('<option value="/SearchResults.asp?Search=creativity">Invoke Creativity');
    
    document.write ('<option value="/SearchResults.asp?Search=fertility">Invoke Fertility');
    
    document.write ('<option value="/SearchResults.asp?Search=friend">Invoke Friendship');
    
    document.write ('<option value="/SearchResults.asp?Search=luck">Invoke Good Fortune');
    
    document.write ('<option value="/SearchResults.asp?Search=wish">Invoke Granting of Wishes');
    
    document.write ('<option value="/SearchResults.asp?Search=happ">Invoke Happiness');
    
    document.write ('<option value="/SearchResults.asp?Search=health">Invoke Health');
    
    document.write ('<option value="/SearchResults.asp?Search=intuit">Invoke Intuition');
    
    document.write ('<option value="/SearchResults.asp?Search=know">Invoke Knowledge');
    
    document.write ('<option value="/SearchResults.asp?Search=lead">Invoke Leadership');
    
    document.write ('<option value="/SearchResults.asp?Search=long">Invoke Long Life');
    
    document.write ('<option value="/SearchResults.asp?Search=love">Invoke Love');
    
    document.write ('<option value="/SearchResults.asp?Search=lust">Invoke Lust');
    
    document.write ('<option value="/SearchResults.asp?Search=magick">Invoke Magickal Ability');
    
    document.write ('<option value="/SearchResults.asp?Search=prosperity">Invoke Prosperity');
    
    document.write ('<option value="/SearchResults.asp?Search=protection">Invoke Protection');
    
    document.write ('<option value="/SearchResults.asp?Search=psychic">Invoke Psychic Ability');
    
    document.write ('<option value="/SearchResults.asp?Search=travel">Invoke Safe Travels');
    
    document.write ('<option value="/SearchResults.asp?Search=strength">Invoke Strength');
    
    document.write ('<option value="/SearchResults.asp?Search=success">Invoke Success');
    
    document.write ('<option value="/SearchResults.asp?Search=obstacles">For Surmounting Obstacles');
    
    document.write ('<option value="/SearchResults.asp?Search=dream">Invoke Sweet Dreams');
    
    document.write ('<option value="/SearchResults.asp?Search=wealth">Invoke Wealth');
    
    document.write ('<option value="/SearchResults.asp?Search=wisdom">Invoke Wisdom');
    
    document.write ('</select>');
    
    document.write ('</form>');
    }
    makeMyMenu();
    // End -->
    </script>
    
    Code (markup):
    * per instructions from someone else I removed the 'makeMyMenu(); from the .js file, but still a no-go.

    In Firefox I get the following errors via the error console:
    I didn't write this code, and I don't know how to write javascript so I don't know what is wrong or how to make it right. Any help would be greatly appreciated, thanks.
     
    freelancing, Jun 19, 2007 IP
  2. Auriga

    Auriga Guest

    Messages:
    155
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    First try to modify the .js file. This should not contain:

    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin

    and

    // End -->
    </script>

    Once you've removed the above lines, also include the full path (as you also suggested in your post) in the call to the javascript:

    <script type="text/javascript" language="Javascript" src="http://www.mydomain.com/somefolder/meaningsearch.js">
    </script>

    This should help you already on the way :D Good luck!
     
    Auriga, Jun 19, 2007 IP
  3. freelancing

    freelancing Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hallelujah I could kiss you! lol

    Thanks so much :D
     
    freelancing, Jun 19, 2007 IP
  4. Auriga

    Auriga Guest

    Messages:
    155
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Depending on your gender i've no problem with that :p
     
    Auriga, Jun 21, 2007 IP