Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-31-2012, 03:04 PM   PM User | #1
Anodos
New Coder

 
Join Date: Aug 2012
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Anodos is an unknown quantity at this point
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
Anodos is offline   Reply With Quote
Old 08-31-2012, 03:27 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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.
xelawho is offline   Reply With Quote
Old 08-31-2012, 03:49 PM   PM User | #3
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 960
Thanks: 7
Thanked 100 Times in 100 Posts
WolfShade is an unknown quantity at this point
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".
WolfShade is offline   Reply With Quote
Old 08-31-2012, 03:52 PM   PM User | #4
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
for some reason I read "folders" as "files"

more coffee req'd
xelawho is offline   Reply With Quote
Old 08-31-2012, 04:20 PM   PM User | #5
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 960
Thanks: 7
Thanked 100 Times in 100 Posts
WolfShade is an unknown quantity at this point
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".
WolfShade is offline   Reply With Quote
Old 09-01-2012, 12:00 AM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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
Quote:
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
Quote:
Are you sure you want to jump to Purchase KINDLE books?
__________________
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.

Last edited by Old Pedant; 09-01-2012 at 12:26 AM..
Old Pedant is offline   Reply With Quote
Old 09-01-2012, 12:22 AM   PM User | #7
Anodos
New Coder

 
Join Date: Aug 2012
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Anodos is an unknown quantity at this point
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.
Anodos is offline   Reply With Quote
Old 09-01-2012, 12:25 AM   PM User | #8
Anodos
New Coder

 
Join Date: Aug 2012
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Anodos is an unknown quantity at this point
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!
Anodos is offline   Reply With Quote
Old 09-01-2012, 12:27 AM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 09-01-2012, 12:28 AM   PM User | #10
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 09-01-2012, 12:28 AM   PM User | #11
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 09-01-2012, 12:44 AM   PM User | #12
Anodos
New Coder

 
Join Date: Aug 2012
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Anodos is an unknown quantity at this point
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...
Anodos is offline   Reply With Quote
Old 09-01-2012, 12:46 AM   PM User | #13
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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.
xelawho is offline   Reply With Quote
Old 09-01-2012, 01:50 AM   PM User | #14
Anodos
New Coder

 
Join Date: Aug 2012
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Anodos is an unknown quantity at this point
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/
Anodos is offline   Reply With Quote
Old 09-01-2012, 02:08 AM   PM User | #15
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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
xelawho is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:20 AM.


Advertisement
Log in to turn off these ads.