By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,678 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,678 IT Pros & Developers. It's quick & easy.

newbie: problem with calling or including .js file

P: n/a
Hello,
I am learning WWW technologies in Linux. I created index.html file which I
can browse with Firefox/Konqueror using URL
localhost/~robert/rozgloszenia/index.html. The page looks fine but there's
one strange problem: I have written some JavaScript code in functions.js
file which seems to be ignored when called although I have JavaScript
enabled in Firefox/Konqueror.

For example in functions.js I have:

function getCurrentYear()
{
var today = Date();
return today.getFullYear();
}

I have written:

<head>
...
<script src="functions.js" language="javascript"
type="text/javascript"></script>
</head>

and then I have:

<script language="javascript"
type="text/javascript">document.write(getCurrentDate());</script>

There's nothing in oputput.

When I have written simple line:

<script language="javascript"
type="text/javascript">document.write('ABC');</script>

output is correct (ABC characters).
But when I put document.write('ABC'); in Test() function in functions.js and
call it:

<script language="javascript" type="text/javascript">Test();</script>

then there's nothing in output.

The file functions.js has -rw-rw-r-- priviledges.

Please help.
Thanks in advance.
/RAM/
Jun 27 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Jun 13, 11:09 am, r_ahims...@poczta.onet.pl wrote:
Hello,
I am learning WWW technologies in Linux. I created index.html file which I
can browse with Firefox/Konqueror using URL
localhost/~robert/rozgloszenia/index.html. The page looks fine but there's
one strange problem: I have written some JavaScript code in functions.js
file which seems to be ignored when called although I have JavaScript
enabled in Firefox/Konqueror.

For example in functions.js I have:

function getCurrentYear()
{
var today = Date();
return today.getFullYear();

}

I have written:

<head>
...
<script src="functions.js" language="javascript"
type="text/javascript"></script>
</head>

and then I have:

<script language="javascript"
type="text/javascript">document.write(getCurrentDate());</script>

There's nothing in oputput.

When I have written simple line:

<script language="javascript"
type="text/javascript">document.write('ABC');</script>

output is correct (ABC characters).
But when I put document.write('ABC'); in Test() function in functions.js and
call it:

<script language="javascript" type="text/javascript">Test();</script>

then there's nothing in output.

The file functions.js has -rw-rw-r-- priviledges.

Please help.
Thanks in advance.
/RAM/
Hi,

I am also a Linux user and have found out that most users of this
newsgroup are not. The people here are usually very helpful but you
need to first identify whether you have a Linux problem, for instance
a permissions problem, or a HTML/Javascript problem.

The easiest way to do this would be to post your index.html and
functions.js files on a server where the newsgroup users can access
them with their own browsers. If the problem is a Javasript (or HTML)
problem they will help you.

Regards,

Steve.
Jun 27 '08 #2

P: n/a
SAM
r_********@poczta.onet.pl a écrit :
Hello,
I am learning WWW technologies in Linux. I created index.html file which I
can browse with Firefox/Konqueror using URL
localhost/~robert/getCurrentYear/index.html. The page looks fine but there's
one strange problem: I have written some JavaScript code in functions.js
file which seems to be ignored when called although I have JavaScript
enabled in Firefox/Konqueror.
and calling the file by :
file://localhost/Users/robert/getCurrentYear/index.html
or something like that
(to see if it's really a pb of privileges)
For example in functions.js I have:

function getCurrentYear()
{
var today = Date();
return today.getFullYear();
}

I have written:

<head>
...
<script src="functions.js" language="javascript"
type="text/javascript"></script>
</head>

and then I have:

<script language="javascript"
type="text/javascript">document.write(getCurrentDate());</script>
could be better with : document.write(getCurrentYear());
no ?

--
sm
Jun 27 '08 #3

P: n/a
r_********@poczta.onet.pl escribió:
localhost/~robert/rozgloszenia/index.html. The page looks fine but there's
one strange problem: I have written some JavaScript code in functions.js
file which seems to be ignored when called although I have JavaScript
enabled in Firefox/Konqueror.
Debugging steps you can take:

1. Check your web server's logs: is the *.js file actually requested? Is
it served successfully?

2. Check Firefox's JavaScript console (Tools menu)

3. Get the Firebug extension for Firefox.
<script src="functions.js" language="javascript"
type="text/javascript"></script>
BTW, the language attribute is deprecated. I suppose you don't validate
your HTML with W3C validator: you should. Extensions like Web Developer
Toolbar for Firefox can help you to validate local HTML or you can just
paste or upload the file:

http://validator.w3.org/
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 27 '08 #4

P: n/a
On Jun 13, 7:15*am, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
r_ahims...@poczta.onet.pl escribió:
localhost/~robert/rozgloszenia/index.html. The page looks fine but there's
one strange problem: I have written some JavaScript code in functions.js
file which seems to be ignored when called although I have JavaScript
enabled in Firefox/Konqueror.

Debugging steps you can take:

1. Check your web server's logs: is the *.js file actually requested? Is
it served successfully?

2. Check Firefox's JavaScript console (Tools menu)

3. Get the Firebug extension for Firefox.
* * * * <script src="functions.js" language="javascript"
type="text/javascript"></script>

BTW, the language attribute is deprecated. I suppose you don't validate
your HTML with W3C validator: you should. Extensions like Web Developer
Toolbar for Firefox can help you to validate local HTML or you can just
paste or upload the file:

http://validator.w3.org/

--
--http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:http://bits.demogracia.com
-- Mi web de humor al baño María:http://www.demogracia.com
--
I also notice that your function defined in the .js file is named
getCurrentYear, yet the one you're attempting to call is
getCurrentDate...

Do you have Firebug or Venkeman installed on your Firefox
installation? It would show if there were any javascript errors.
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.