Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 21st, 2005, 8:09 PM   #1
aznluvsmc
Hobbyist Programmer
 
Join Date: Aug 2005
Posts: 137
Rep Power: 4 aznluvsmc is on a distinguished road
HTML page not reading external Javascript file

Hi,

My HTML page is not reading my external javascript file. I don't see anything I did wrong in the declaration so I'm stumped. Can someone spot something I don't see?

<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
	<link rel='stylesheet' href='mystyle.css' type='text/css' media='screen' />
	<script type='text/javascript' src='myscript.js'></script>
	<title>Javascript Test</title>
</head>

<body onload='loaded()'>

The loaded function just has an alert box that pops up with some text which I was using to test the Javascript functionality. I've verified that the javascript file exists with the proper .js extension in the current directory. Javascript is enabled on my browser as I've tested local code to ensure it works. I'm having the problem on both IE and Firefox.
aznluvsmc is offline   Reply With Quote
Old Nov 21st, 2005, 8:27 PM   #2
Agent 47
Hobbyist Programmer
 
Agent 47's Avatar
 
Join Date: Nov 2005
Posts: 122
Rep Power: 4 Agent 47 is on a distinguished road
That code looks fine. Can you post the JS too please? Make sure the
file is called 'myscript.js' too [case sensitive ;]

--47.
__________________
"I'm going to become rich and famous when I invent a device that allows you to stab people in the face over the internet"
Agent 47 is offline   Reply With Quote
Old Nov 21st, 2005, 8:38 PM   #3
aznluvsmc
Hobbyist Programmer
 
Join Date: Aug 2005
Posts: 137
Rep Power: 4 aznluvsmc is on a distinguished road
function loaded() {
	alert("reading");
}

function checkLength(string, min, max) {
	var rv = true;

	if (string.length < min || string.length > max) {
		rv = false;
	}

	return rv;
}

function charPos(string, char, pos) {
	var rv = true;

	if (string.indexOf(char) != (pos - 1)) {
		rv = false;
	}

	return rv;
}

function isInt(string) {
	var rv = true;

	for (var i = 0; i < string.length && rv; i++) {
		if (isNaN(string.charAt(i))) {
			rv = false;
		}
	}

	return rv;
}

function digitSum(string) {
	var sum = 0;		

	if (isNaN(string)) {
		sum = -1;
	}
	else {
		for (var i = 0; i < string.length; i++) {
			sum += parseInt(string.charAt(i));
		}
	}

	return sum;
}

function alpha(string) {
	var rv = true;

	for (var i = 0; i < string.length && rv; i++) {
		if (string.toUpperCase.charAt(i) < 'A' || string.toUpperCase.charAt(i) > 'Z') {
			rv = false;
		}
	}

	return rv;
}

I think the problem might be due to an error in one of the functions which is stopping the whole script from being read. I was doing some testing and discovered that if one piece of the code is wrong, the whole thing doesn't run which is weird. Anyways, I'm not sure where my problem is.
aznluvsmc is offline   Reply With Quote
Old Nov 21st, 2005, 8:45 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
It isn't really weird. If there's an error, there's not much point in proceeding. It will depend mainly upon whether or not the error dinks up subsequent parsing. Did you pop up the Javascript Console and see if it had news for you?

EDIT: Incidentally, using tokens like "min" and "max", even though they don't cause a problem under the circumstances, is stylistically shaky and potentially perilous when they're keywords for other things, like Math methods.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 21st, 2005, 8:49 PM   #5
aznluvsmc
Hobbyist Programmer
 
Join Date: Aug 2005
Posts: 137
Rep Power: 4 aznluvsmc is on a distinguished road
Sorry I'm really new to Javascript and have never heard of the Javascript Console (or maybe not in those terms). Where can I find it?
aznluvsmc is offline   Reply With Quote
Old Nov 21st, 2005, 8:54 PM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
In Internet Explorer, if I recall correctly, if there's an error, a little yellow and grey icon will appear in the bottom-left of the window. Double-click it.

More useful is Firefox's Javascript Console. If you use Firefox (and I suggest you try it if you don't), you can access the console by clicking Tools -> JavaScript Console - it'll let you know of any errors or warnings.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 21st, 2005, 8:56 PM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
On Firefox, click Tools | Javascript Console. On IE, set your advanced preferences to enable script debugging and display notification errors.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 21st, 2005, 8:57 PM   #8
aznluvsmc
Hobbyist Programmer
 
Join Date: Aug 2005
Posts: 137
Rep Power: 4 aznluvsmc is on a distinguished road
Thank you, I just learned something new. I've been using Firefox for a while but never really noticed the Javascript Console option. I figured out that the problem was from using the variable char as a formal parameter.
aznluvsmc is offline   Reply With Quote
Old Nov 21st, 2005, 8:59 PM   #9
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
If you install the Web Developer Plugin for Firefox, you get a funky button that gives you access to it and lets you know whether there's a warning or an error.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 21st, 2005, 10:17 PM   #10
aznluvsmc
Hobbyist Programmer
 
Join Date: Aug 2005
Posts: 137
Rep Power: 4 aznluvsmc is on a distinguished road
I just installed it. Thanks for the info, don't know how I'd get through my Javascript class without it.
aznluvsmc is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:38 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC