...

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



SpeedFreak
12-19-2003, 12: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.

Cheers

glenngv
12-19-2003, 12:55 PM
<html>
<head>
<script type="text/javascript">
function changeText(txt){
document.getElementById("mydiv").innerHTML=txt;
return false;
}
</script>
</head>
<body>
<a href="#" onclick="return changeText('cheese')">cheese</a>
<a href="#" onclick="return changeText('<b>text</b>')">bold text</a>
<div id="mydiv">mouse</div>
</body>
</html>

SpeedFreak
12-19-2003, 02: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....

Tails
12-20-2003, 05: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.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum