![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Aug 2005
Posts: 137
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Nov 2005
Posts: 122
Rep Power: 3
![]() |
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" |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Aug 2005
Posts: 137
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Aug 2005
Posts: 137
Rep Power: 3
![]() |
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?
|
|
|
|
|
|
#6 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8
![]() |
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. |
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#8 |
|
Hobbyist Programmer
Join Date: Aug 2005
Posts: 137
Rep Power: 3
![]() |
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.
|
|
|
|
|
|
#9 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8
![]() |
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.
![]() |
|
|
|
|
|
#10 |
|
Hobbyist Programmer
Join Date: Aug 2005
Posts: 137
Rep Power: 3
![]() |
I just installed it. Thanks for the info, don't know how I'd get through my Javascript class without it.
![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|