Enjoy an ad free experience by logging in. Not a member yet?
Register .
08-31-2012, 03:04 PM
PM User |
#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
08-31-2012, 03:27 PM
PM User |
#2
Senior Coder
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 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.
08-31-2012, 03:49 PM
PM User |
#3
Regular Coder
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 960
Thanks: 7
Thanked 100 Times in 100 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".
08-31-2012, 03:52 PM
PM User |
#4
Senior Coder
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
for some reason I read "folders" as "files"
more coffee req'd
08-31-2012, 04:20 PM
PM User |
#5
Regular Coder
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 960
Thanks: 7
Thanked 100 Times in 100 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".
09-01-2012, 12:00 AM
PM User |
#6
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 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
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 ..
09-01-2012, 12:22 AM
PM User |
#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.
09-01-2012, 12:25 AM
PM User |
#8
New Coder
Join Date: Aug 2012
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
Old Pedant
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!
09-01-2012, 12:27 AM
PM User |
#9
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 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.
09-01-2012, 12:28 AM
PM User |
#10
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 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.
09-01-2012, 12:28 AM
PM User |
#11
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 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.
09-01-2012, 12:44 AM
PM User |
#12
New Coder
Join Date: Aug 2012
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
Old Pedant
Show your *full* HTML page. From <html> to </html>.
I did, in the original post.
I was joking about the wizard. I hope...
09-01-2012, 12:46 AM
PM User |
#13
Senior Coder
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 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.
09-01-2012, 01:50 AM
PM User |
#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/
09-01-2012, 02:08 AM
PM User |
#15
Senior Coder
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 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
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 04:20 AM .
Advertisement
Log in to turn off these ads.