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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    New Coder
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    function not defined due to me having no idea what im doing.

    Hi, I just started learning Javascript, and ive been at this all night and i have no idea what im doing.

    Ive never made a webpage before, and putting code into two separate folders is new to me, and i have no idea why it cant find the code. So just put this here and you tell me what im doing wrong?
    This is my index file...
    Code:
    <html>
     
    <head>
     
     
    <SCRIPT LANGUAGE="Javascript" SRC="student.js" > 
    </script>
     
    <center>
     
    <h1>McDonalds</h1>
     
    @
     
    <h1>The Largest George Mcdonald Bookstore on the Web!</h1>
     
    </head>
     
    <body>
    <BR />
     
    <BR />
     
    <BR />
     
    <BR />
     
    <BR />
     
    <BR />
     
    <A HREF="Javascript:confirmlink(http://www.amazon.com/s/ref=nb_sb_ss_c_0_15?url=search-alias%3Dstripbooks&field-keywords=george+macdonald&sprefix=george+mcdonald%2Caps%2C192
     
    )">Purchase Books!</A>
     
    <A HREF="Javascript:confirmlink('http://www.amazon.com/s/ref=sr_nr_p_n_feature_browse-b_2?rh=n%3A283155%2Ck%3Ageorge+mcdonald%2Cp_n_feature_browse-bin%3A618073011&bbn=283155&keywords=george+mcdonald&ie=UTF8&qid=1346409960&rnid=618072011
     
    ')">Purchase KINDLE books!</A>
     
    <p>Favorite Links</p>
     
    <A HREF="Javascript:confirmlink('http://www.college1.com/users/brandon.taylor.james@gmail.com
     
    ')">college</A>
     
    </script>
     
     
     
     
     
    </body>
     
    </html>

    and this is my .js file

    Code:
    <SCRIPT LANGUAGE="Javascript">
    function confirmlink(linkname) { 
       if (confirm("Are you sure you want to jump to " + linkname + "?")) 
            location = linkname 
    } 
     
     
     
    </SCRIPT>

    Post everything, like I said, dont know where the problem is.

    So if you can just point out the error, it will retain in my brain forever, hopefully.

    Thanks in advance

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    there are many problems which will probably not cause your code to fail, but are antiquated approaches nonetheless.

    - the major one is that a separate js file should not have <script> tags in it. This is probably the fatal error
    - another killer is that your first link href needs apostrophes like the others have
    - a troubling one is that <SCRIPT LANGUAGE="Javascript"> is very ancient. To link to an external file you can use
    Code:
    <script src="student.js" type="text/javascript"></script>
    - this is also heavily outdated, but will still work:
    Code:
    <A HREF="Javascript:confirmlink('http://www.amazon.com/s/ref=sr_nr_p_n_feature_browse-b_2?rh=n%3A283155%2Ck%3Ageorge+mcdonald%2Cp_n_feature_browse-bin%3A618073011&bbn=283155&keywords=george+mcdonald&ie=UTF8&qid=1346409960&rnid=618072011')">Purchase KINDLE books!</A>
    it should be more like this:
    Code:
    <a href="#" onclick="confirmlink('http://www.amazon.com/s/ref=sr_nr_p_n_feature_browse-b_2?rh=n%3A283155%2Ck%3Ageorge+mcdonald%2Cp_n_feature_browse-bin%3A618073011&bbn=283155&keywords=george+mcdonald&ie=UTF8&qid=1346409960&rnid=618072011'); return false">Purchase KINDLE books!</a>
    for all those links.

    there are fancier ways of doing what you are trying to do, but those are the quick fixes I can see.

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    The OP also mentioned "putting code into two separate folders". If the .js file is in another folder, that folder needs to be part of the SRC attribute of the SCRIPT tag (ie, <script src="folderName/student.js"></script> if the folder is below the current folder, or <script src="/folderName/student.js"></script> if the folder is immediately below the web root folder.)
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    for some reason I read "folders" as "files"

    more coffee req'd

  • #5
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    I hear ya! Every morning a few of us walk from the office to the coffee shop across the parking lot (the "Caffeine Parade" the bosses call it). I don't drink coffee, but I do drink caffeinated soda/pop, and cannot function without it.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,198
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    A better way, all around, to do this:

    It works even if the user has JavaScript disabled. (If so, then the confirm doesn't show up, but the link works anyway.)

    Code:
    <a href="http://www.amazon.com/s/ref=...etc..." onclick="return confirmlink(this);">Purchase KINDLE books</a>
    and then:
    Code:
    <script type="text/javascript">
    function confirmlink( link )
    {
         return confirm("Are you sure you want to jump to " + link.innerHTML+ "?");
    } 
    </script>
    you don't *REALLY* want to ask the user
    Are you sure you want to jump to http://www.amazon.com/s/ref=sr_nr GOBBLEDY GOOK TO USER ...?
    which is what will happen with any of the above answers.

    Instead, my code will ask
    Are you sure you want to jump to Purchase KINDLE books?
    Last edited by Old Pedant; 09-01-2012 at 12:26 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    New Coder
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Op here. Sorry, i meant files not folders. Tired....


    Tried your examples. What i thought, there is just simply a WIZARD preventing me from completing my task.


    I should of mentioned i went to the debug and it said, of course, "cant find Confirmlink" or something.

    But now it doesnt say that...and it still doesnt work.

    Put your codes in there, still doesnt work.

    Dam wizard.

  • #8
    New Coder
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    A better way, all around, to do this:

    It works even if the user has JavaScript disabled. (If so, then the confirm doesn't show up, but the link works anyway.)

    Code:
    <a href="'http://www.amazon.com/s/ref=...etc..." onclick="return confirmlink(this);">Purchase KINDLE books</a>
    and then:
    Code:
    <script type="text/javascript">
    function confirmlink( link )
    {
         return confirm("Are you sure you want to jump to " + link.innerHTML+ "?");
    } 
    </script>
    you don't *REALLY* want to ask the user

    which is what will happen with any of the above answers.

    Instead, my code will ask
    Youre right about the gobblygook. Im just doing what im told, but even the un gobblygook links dont work.

    I have to find out why perfectly good code isnt working as it is, anyway. Even if your new way works, isnt what i was told to do...


    GAAAHHHHH!

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,198
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    What "wizard"? Why are you using a wizard? What kind?

    Caution: JavaScript is case sensitive. confirmlink is *NOT* the same as Confirmlink or confirmLink or ConfirmLink.

    Yes, the code does work.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,198
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    My original post had a bogus extra ' in the HREF. But I fixed that it and it works fine.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,198
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    Show your *full* HTML page. From <html> to </html>.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #12
    New Coder
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Show your *full* HTML page. From <html> to </html>.
    I did, in the original post.


    I was joking about the wizard. I hope...

  • #13
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    so show us the updated version of both files. wizard or not, if you haven't fixed at least a couple of things I pointed out above, your code doesn't stand a chance.

  • #14
    New Coder
    Join Date
    Aug 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Heres the code
    Code:
    <html>
     
    <head>
     
     
     
     
    <center>
     
    <h1>McDonalds</h1>
     
     
     
    <h1>The Largest George Mcdonald Bookstore on the Web!</h1>
     
    </head>
     
    <body>
    <BR />
     
    <BR />
     
    <BR />
     
    <BR />
     
    <BR />
     
    <BR />
     
     
    <p>Favorite Links</p>
     
    <script src="student.js" type="text/javascript"></script>
    </script>
     
    <A HREF="Javascript: confirmlink(http://www.amazon.com/s/ref=nb_sb_ss_c_0_15?url=search-alias%3Dstripbooks&field-keywords=george+macdonald&sprefix=george+mcdonald%2Caps%2C192
     
    )">Purchase Books!</A>
     
    <A HREF="Javascript:confirmlink('http://www.amazon.com/s/ref=sr_nr_p_n_feature_browse-b_2?rh=n%3A283155%2Ck%3Ageorge+mcdonald%2Cp_n_feature_browse-bin%3A618073011&bbn=283155&keywords=george+mcdonald&ie=UTF8&qid=1346409960&rnid=618072011
     
    ')">Purchase KINDLE books!</A>
     
     
    <A HREF="Javascript:confirmlink('http://www.college1.com/users/brandon.taylor.james@gmail.com
     
    ')">college</A>
     
     
    <A HREF="Javascript:confirmlink('http://www.amazon.com/s/ref=sr_nr_p_n_feature_browse-b_2?rh=n%3A283155%2Ck%3Ageorge+mcdonald%2Cp_n_feature_browse-bin%3A618073011&bbn=283155&keywords=george+mcdonald&ie=UTF8&qid=1346409960&rnid=618072011')">Purchase KINDLE books!</A>
     
    <a href="#" onclick="confirmlink('http://www.amazon.com/s/ref=sr_nr_p_n_feature_browse-b_2?rh=n%3A283155%2Ck%3Ageorge+mcdonald%2Cp_n_feature_browse-bin%3A618073011&bbn=283155&keywords=george+mcdonald&ie=UTF8&qid=1346409960&rnid=618072011'); return false">Purchase KINDLE books!</a>
     
     
    </script>
     
     
     
     
     
    </body>
     
    </html>

    Heres the website.

    So frustrating...

    http://anodos.uphero.com/

  • #15
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    1. you need to take the <SCRIPT LANGUAGE="Javascript"> out of your js file.

    2. You need to put apostrophes in your first link, like you have with the other ones:
    Code:
    <A HREF="Javascript: confirmlink('http://www.amazon.com/s/ref=nb_sb_ss_c_0_15?url=search-alias%3Dstripbooks&field-keywords=george+macdonald&sprefix=george+mcdonald%2Caps%2C192')">Purchase Books!</A>
    you have random </script> closing tags and other horrible html, but fixing the above two problems (as I suggested hours ago) should at least get the page working


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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