Simon Johnson

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromSimon Johnson
ToMe
SubjectCalling text from an external javascript file
Date12 December 2007 15:35
Hi, this will sound uterly n00by, but i'm a little frustrated

I want to have a series of links at the top of a page, upon clicking that
link, a body of text will appear beneath, and this will contextually change
depending on the link that has been clicked. My idea was to store each body
of text in a separate javascript file containing just

Tex1 = "The body of text here - Example 1"

I would then define the script in the head, and when I click the link it
should display the text using...

   <a href="#" onclick="document.write(text1)"><font color="#009900"
face="Arial, Helvetica, sans-serif">Text 1 Link/font></a>

I think the problem is that it doesnt know where to actually write the text
too? Could you give me some help please?

Yours truly
Simon Johnson
FromMe
ToSimon Johnson
SubjectRe: Calling text from an external javascript file
Date14 December 2007 18:57
Attachmentsimple demo
Simon,

> I want to have a series of links at the top of a page, upon clicking
> that link, a body of text will appear beneath

Easy.

> My idea was to store each body of text in a separate javascript file
> containing just

That is not a good approach. If the user has JavaScript disabled or
unavailable for whatever reason, this content will be completely
inaccessible.

The best way is to include it as divs within the page. A script can then
hide all of them as the page is loading. The links can then link to the divs
using internal #id links, and when script is enabled, it can intercept this,
show the relevant div, and hide all the others. When script is disabled, it
will simply scroll to the correct div, leaving it perfectly accessible.

I have attached a simple example.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromSimon Johnson
ToMe
SubjectRe: Calling text from an external javascript file
Date17 December 2007 09:27
Thanks for all of the help dude, I should be able to sort this thing out
now.
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.