external javascript not working

N

none

Hi all,

Still pretty new to html. At the risk of showing everyone my private
information I have my homepage http://users.tpg.com.au/jennlion/.

You will see that it is pretty much a blank page with only a title. I'm
including a small amount of javascript so that I can have a reusable
menu on the left hand side, but for some reason when I include the
javascript in a separate file and use the src="Navigation.js" attribute,
the page breaks as you can see. It works on my development machine for
some reason, regardless of browser.

I guess there are two questions here, why is it not working, and what is
the best way to have a reusable menu of links down the left hand side?

Thanks

Lionel.
 
P

Peter J Ross

Hi all,

Still pretty new to html. At the risk of showing everyone my private
information I have my homepage http://users.tpg.com.au/jennlion/.

You will see that it is pretty much a blank page with only a title. I'm
including a small amount of javascript so that I can have a reusable
menu on the left hand side, but for some reason when I include the
javascript in a separate file and use the src="Navigation.js" attribute,
the page breaks as you can see. It works on my development machine for
some reason, regardless of browser.

I guess there are two questions here, why is it not working,

As far as I can see, it *is* working. Have you changed something since
posting?
and what is the best way to have a reusable menu of links down the
left hand side?

Don't use javascript. The menu will disappear for users who have
javascript turned off and navigation around the site will be impossible.

If you don't want to paste the menu into every page, you could use PHP
to include it.

I suggest you fix the various errors in your XHTML first:

<http://validator.w3.org/check?uri=http://users.tpg.com.au/jennlion/Index.html>

Also, in Index.html, both images have the same "alt" attribute.
 
R

Robin Rattay

You will see that it is pretty much a blank page with only a title. I'm
including a small amount of javascript so that I can have a reusable
menu on the left hand side,

You don't need to (read: shouldn't) use JavaScript for that. Reused
content should be included either with a server-side scripting
language (such as PHP) or server-side include. If your provider
doesn't support that, then there are authoring tools that can be used.
I like includeHTML: http://software.rosenlundnielsen.dk/software/product_includehtml.php
but for some reason when I include the
javascript in a separate file and use the src="Navigation.js" attribute,
the page breaks as you can see. It works on my development machine for
some reason, regardless of browser.

Your XHTML is very broken. I'd suggest you'd read up on the basics of
XHTML syntax. Here's a nice tutorial: http://www.htmldog.com/

You can check your syntax with a validator: http://validator.w3.org/

Some basic points:
- All content (including your headline) must go into the <body>.
- Speaking of headline: Instead of wrapping up your headline in
multiple elements (div, big, span, font), use *one* fitting element -
in this case <h1>...</h1> for the main (level 1) headline - and style
it (font size, boldness, centering) in the CSS.
- In XHTML (not HTML) all empty elements (such as link or br) must
end with a slash (/) in the tag: <link ... /> and <br/>
- Some elements *can* be empty (such as script), however IE barfs on
those, if written as <script ... />. In these cases always use
<script ...></script>.

Robin
 
N

none

Peter said:
As far as I can see, it *is* working. Have you changed something since
posting?

It works on my linux box using Firefox 2.X. This is where I develop it.
It doesn't work in IE on XP running in Virtual box, or on a pure XP
laptop with either firefox 3 or IE 6.

Don't use javascript. The menu will disappear for users who have
javascript turned off and navigation around the site will be impossible.

If you don't want to paste the menu into every page, you could use PHP
to include it.

I suggest you fix the various errors in your XHTML first:

<http://validator.w3.org/check?uri=http://users.tpg.com.au/jennlion/Index.html>

Also, in Index.html, both images have the same "alt" attribute.

Thanks, I'll work on your suggested improvements.

Lionel.
 
N

none

Robin said:
You don't need to (read: shouldn't) use JavaScript for that. Reused
content should be included either with a server-side scripting
language (such as PHP) or server-side include. If your provider
doesn't support that, then there are authoring tools that can be used.
I like includeHTML: http://software.rosenlundnielsen.dk/software/product_includehtml.php


Your XHTML is very broken. I'd suggest you'd read up on the basics of
XHTML syntax. Here's a nice tutorial: http://www.htmldog.com/

You can check your syntax with a validator: http://validator.w3.org/

Some basic points:
- All content (including your headline) must go into the <body>.
- Speaking of headline: Instead of wrapping up your headline in
multiple elements (div, big, span, font), use *one* fitting element -
in this case <h1>...</h1> for the main (level 1) headline - and style
it (font size, boldness, centering) in the CSS.
- In XHTML (not HTML) all empty elements (such as link or br) must
end with a slash (/) in the tag: <link ... /> and <br/>
- Some elements *can* be empty (such as script), however IE barfs on
those, if written as <script ... />. In these cases always use
<script ...></script>.

Thanks for the pointers, will follow your suggestions and links and look
at getting nice HTML before debugging again. Hopefully I will solve the
problem while fixing the code!

Thanks

Lionel.
 
D

dorayme

Robin Rattay said:
You don't need to (read: shouldn't) use JavaScript for that. Reused
content should be included either with a server-side scripting
language (such as PHP) or server-side include.

There is absolutely no need to do this at this stage. First things
first. Don't just head off on these geeky paths for the heck of it or
because people say to do it.

But do get rid of the javascript for menu and use an unordered list html
element. Simple and reliable and you just repeat the very little you
would have on the few pages you have. If the site becomes much bigger,
it is a different story and you would need to be looking at "including"
the menu (meaning you write it once and put it in one place and each
page fetches it automatically).
 
N

none

dorayme said:
But do get rid of the javascript for menu and use an unordered list html
element. Simple and reliable and you just repeat the very little you
would have on the few pages you have. If the site becomes much bigger,
it is a different story and you would need to be looking at "including"
the menu (meaning you write it once and put it in one place and each
page fetches it automatically).


I can't agree with repeating the code. I may only have about a dozen
files, but every time I add a new page or change a name I don't want to
be making sure every menu is up-to-date, that is crazy in my opinion and
has already caused me on this site to get menus out of synch!
 
D

dorayme

[QUOTE="none said:
But do get rid of the javascript for menu and use an unordered list html
element. Simple and reliable and you just repeat the very little you
would have on the few pages you have. If the site becomes much bigger,
it is a different story and you would need to be looking at "including"
the menu (meaning you write it once and put it in one place and each
page fetches it automatically).


I can't agree with repeating the code. I may only have about a dozen
files, but every time I add a new page or change a name I don't want to
be making sure every menu is up-to-date, that is crazy in my opinion and
has already caused me on this site to get menus out of synch![/QUOTE]

In that case don't repeat the code. Use an include.

With so few pages, it seems to me too simple a job. You can insure all
are the same via your text editor's ability to find and replace, it is
all pretty automatic and takes the drudgery out of things. True, you do
then have to reload all 12 or so pages up to the server... Perhaps I
have become too used to so simple a system that never confuses or
burdens me until the site becomes rather larger.

You will like PHP includes, I can see. Very handy. Good luck.
 
N

none

dorayme said:
You will like PHP includes, I can see. Very handy. Good luck.

Not supported by my server I discovered :(.

If I ever use copy and paste without changes then it is always time to
extract common code.

I'm a Software Engineer, but clearly I have not much idea what I'm doing
when it comes to html, php and javascript, I've never really done any
web stuff.
 
R

Roy A.

It works on my linux box using Firefox 2.X. This is where I develop it.
It doesn't work in IE on XP running in Virtual box, or on a pure XP
laptop with either firefox 3 or IE 6.

HTML Tag soup parsers don't understand neither the sgml nor the xml
shorthand '/'.

Just change:

<script type="text/javascript" src="Navigation.js"/>

to:

<script type="text/javascript" src="Navigation.js"></script>
 
D

dorayme

[QUOTE="none said:
You will like PHP includes, I can see. Very handy. Good luck.

Not supported by my server I discovered :(.

If I ever use copy and paste without changes then it is always time to
extract common code.

I'm a Software Engineer, but clearly I have not much idea what I'm doing
when it comes to html, php and javascript, I've never really done any
web stuff.[/QUOTE]

Which is really why I said to not bother with includes yet. You need to
run before you walk. You already know how to copy and paste, you do not
need to learn this. But you don't know the basics of HTML and CSS,
otherwise you would have employed an HTML unordered list for your
navigation. Better to spend time on learning these basics than to be
overly concerned about having to cut and paste a bit and to be chasing
off after more sophisticated technologies. Cart before the horse and all
that...
 
N

none

Roy said:
HTML Tag soup parsers don't understand neither the sgml nor the xml
shorthand '/'.

Just change:

<script type="text/javascript" src="Navigation.js"/>

to:

<script type="text/javascript" src="Navigation.js"></script>

Right you are. Thanks :).
 
N

none

mbstevens said:
Just kidding around, but, yeah, if you call
cat with it. An HTML preprocessor might make
more sense.

Not necessarily. I have managed to fully automated the process with a 10
line shell script :). No necessary download and learning of new tools!
 
S

Sherm Pendley

none said:
You can do it with make?

Sure - there's no reason why make would only be usable to compile
software. Here's the makefile I use to create the CamelBones site from
XML documents, using xsltproc, and 'install' and 'sync' targets to
copy the site to a staging and the live server, respectively.

It works a treat - all I do to add a page is create its xml, add it to
the navigation.xml where I want its menu item to be, and 'make
install'.

sherm--

# make file for CBDocs

# Useful definitions
XSLTPROC = /usr/bin/xsltproc
FOP = /Users/sherm/bin/fop.sh
TIDY = /usr/bin/tidy
SITES = /Users/sherm/Sites
INSTALL = /usr/bin/install
RSYNC = /usr/bin/rsync

XSL_HTML_STYLESHEET = html.xsl
NAV_XML = navigation.xml
XSL_FO_STYLESHEET = fo.xsl

# Get the list of files
HTML = $(shell $(XSLTPROC) htmldocs.xsl navigation.xml)
HTML_DIRS = $(shell $(XSLTPROC) htmldirs.xsl navigation.xml)

# Targets:
all: html

html: $(HTML_DIRS) $(HTML)

$(HTML_DIRS):
mkdir -p $(HTML_DIRS)

pdf: $(PDF) $(IMAGES) $(XSL_FO_STYLESHEET)

%.html : %.xml $(XSL_HTML_STYLESHEET) $(NAV_XML)
$(XSLTPROC) --stringparam docname $< -o $@ $(XSL_HTML_STYLESHEET) $<
$(TIDY) -modify -indent -quiet --doctype strict $@

%.fo : %.xml
$(XSLTPROC) -o $@ $(XSL_FO_STYLESHEET) $<

%.pdf : %.fo
$(FOP) $< $@

install: install_html

install_html: html
$(RSYNC) --recursive \
--exclude=*.xml --exclude=*.xsl --exclude=GNUmakefile* \
--exclude=CVS --exclude=.DS_Store \
. $(SITES)

sync: install_html
$(RSYNC) --recursive --exclude=.DS_Store \
$(SITES)/* $(SITES)/.htaccess \
"(e-mail address removed):/home/groups/c/ca/camelbones/htdocs/"

clean:
rm -f $(HTML) $(PDF)
 
L

Lionel

dorayme said:
Which is really why I said to not bother with includes yet. You need to
run before you walk. You already know how to copy and paste, you do not
need to learn this. But you don't know the basics of HTML and CSS,
otherwise you would have employed an HTML unordered list for your
navigation.

I still stand by not doing this. If I get it wrong once then I get it
wrong a dozen times, it's just bad practice. It would be great if html
had some sort of include tag but unless someone comes and points out
that it does, then AFAIK it doesn't.

FYI in my first draft of that web page I did use a <ul>...</ul> and I
did have it repeated 12 times. My lists consistently got out of synch
while I tried to copy and paste making sure I didn't leave a tag hanging
accidentally etc. It was horrible!
 
D

dorayme

[QUOTE="Lionel said:
Which is really why I said to not bother with includes yet. You need to
run before you walk. You already know how to copy and paste, you do not
need to learn this. But you don't know the basics of HTML and CSS,
otherwise you would have employed an HTML unordered list for your
navigation.

I still stand by not doing this. If I get it wrong once then I get it
wrong a dozen times, it's just bad practice. It would be great if html
had some sort of include tag but unless someone comes and points out
that it does, then AFAIK it doesn't.

FYI in my first draft of that web page I did use a <ul>...</ul> and I
did have it repeated 12 times. My lists consistently got out of synch
while I tried to copy and paste making sure I didn't leave a tag hanging
accidentally etc. It was horrible![/QUOTE]

If you are having such difficulty with this, how can you be so confident
that you won't have as many difficulties with mastering includes, making
sure the HTML doc has a correct file path to get to the include on the
server, putting the includes on the server, putting in the references to
the includes into each page. This is also a job that requires
repeatition. If you can't cut and paste accurately, then you can run
into trouble here too. There are fiddly little greater than signs,
question marks and so on in include references. All of them have to be
repeated page after page.

In the end, it is actually important that you master not getting the
basics wrong. Cut and paste is basics. Making web sites is fiddly work
and requires a lot of attention to detail. When you get the basics right
(not wrong) and get fed up, then is the time to get more sophisticated.

And no, I can't agree with your maths. (My, how disagreeable I am!).
You personally don't have to repeat anything 12 times if you use Search
and Replace in your text editor, technology which is dead easy to
master. You search for the old menu text and you replace it with new
over a number of pages in a folder. Get it right once and you are good
to go for changes a million times.

Not trying to be mean to you. It is just that it seems so obvious that
you must stop and get rock bottom basics right before looking for fancy.
 
N

none

dorayme said:
[QUOTE="Lionel said:
Which is really why I said to not bother with includes yet. You need to
run before you walk. You already know how to copy and paste, you do not
need to learn this. But you don't know the basics of HTML and CSS,
otherwise you would have employed an HTML unordered list for your
navigation.
I still stand by not doing this. If I get it wrong once then I get it
wrong a dozen times, it's just bad practice. It would be great if html
had some sort of include tag but unless someone comes and points out
that it does, then AFAIK it doesn't.

FYI in my first draft of that web page I did use a <ul>...</ul> and I
did have it repeated 12 times. My lists consistently got out of synch
while I tried to copy and paste making sure I didn't leave a tag hanging
accidentally etc. It was horrible!

If you are having such difficulty with this, how can you be so confident
that you won't have as many difficulties with mastering includes, making
sure the HTML doc has a correct file path to get to the include on the
server, putting the includes on the server, putting in the references to
the includes into each page. This is also a job that requires
repeatition. If you can't cut and paste accurately, then you can run
into trouble here too. There are fiddly little greater than signs,
question marks and so on in include references. All of them have to be
repeated page after page.

In the end, it is actually important that you master not getting the
basics wrong. Cut and paste is basics. Making web sites is fiddly work
and requires a lot of attention to detail. When you get the basics right
(not wrong) and get fed up, then is the time to get more sophisticated.

And no, I can't agree with your maths. (My, how disagreeable I am!).
You personally don't have to repeat anything 12 times if you use Search
and Replace in your text editor, technology which is dead easy to
master. You search for the old menu text and you replace it with new
over a number of pages in a folder. Get it right once and you are good
to go for changes a million times.

Not trying to be mean to you. It is just that it seems so obvious that
you must stop and get rock bottom basics right before looking for fancy.[/QUOTE]

Yeah, many a text editor can do search and replace, but it is unlikely
to do blocks all that well and it is unlikely to open the 12 files all
by itself, what you said doesn't make much sense. Of course I could use
sed or something like that.

I'm not trying to be fancy, I'm trying to be practical and exercise code
reuse. My page is now working with JS, I don't care if any of my target
audience doesn't have JS enabled as this is very unlikely anyway.

Sure I had some poor design stuff in that page (and the others which I'm
yet to fix) but that will improve with time.

I don't agree with your approach so I might leave it at that. Everyone
has a different learning style.

I thank everyone including yourself for the valuable input though :).

Lionel.
 
D

dorayme

none <""lionel\"@(none)"> said:
Yeah, many a text editor can do search and replace, but it is unlikely
to do blocks all that well and it is unlikely to open the 12 files all
by itself, what you said doesn't make much sense. Of course I could use
sed or something like that.

On what do you base your opinion that many a text editor is unlikely
to do blocks all that well? I know for a fact that my text editor is
extremely reliable in this regard. There would be many others as good.
Perhaps it is something you are not noticing that is giving you an
impression of unreliability?

Apart from this unreliability you are claiming, is there anything else
that does not make sense? Remember, we are talking 12 pages and a very
small menu indeed. A very nice menu, mind you, but very modest in
complexity.
I'm not trying to be fancy, I'm trying to be practical and exercise code
reuse. My page is now working with JS, I don't care if any of my target
audience doesn't have JS enabled as this is very unlikely anyway.

Well, I won't get into this javascript issue, others have spoken well on
this. Please accept that I came in only because I saw you possibly
chasing after "includes" - which are very good things - while seeming to
be having so much trouble with simple HTML and copy and paste and this
sounded like some cart was getting in front of some horse given you had
12 pages and a very simple list.
I don't agree with your approach so I might leave it at that. Everyone
has a different learning style.

I am biased, I see my view as urging you to walk to the shops that are
about 100 metres away rather than start up the car and risk running out
of petrol, running into the neighbours cat, contributing to global
warming, bringing peak-oil closer ... <g>

But good luck anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top