View Full Version : getting a link to change a peice of text...

12-19-2003, 01:42 PM
Hey there,

I have a pretty simple idea, i just want a link to change a peice of text to something else. eg if the text says 'mouse' and i click a link 'cheese' i want the text to change to 'cheese' i know i can pass what i want the text to become to a javascript function but im not sure how to change the text.


12-19-2003, 01:55 PM
<script type="text/javascript">
function changeText(txt){
return false;
<a href="#" onclick="return changeText('cheese')">cheese</a>
<a href="#" onclick="return changeText('<b>text</b>')">bold text</a>
<div id="mydiv">mouse</div>

12-19-2003, 03:11 PM
thanks for that, works nicely.

this has got me thinking, is there a way for javascript to get the text that its gonna change to from a .txt file?

coz you could use this as a replacement for small iframes if javascript could do that....

12-20-2003, 06:36 AM
Javascript alone can't red an external file. But you could store a variable (or array of variables) in an external script file for easy mainenance. This would probably be the best solution if you are using this script on many pages.

Oh yea, I document.write() my email on many pages all by calling a single script file. darn Tripod spyders.

12-20-2003, 06:45 PM
CHeck this (http://codingforums.com/showthread.php?s=&threadid=30449) thread out for more information.