Click to See Complete Forum and Search --> : changing text inside a layer everytime a link is clicked


sherbhet
04-10-2003, 01:03 AM
Hi, i'm kinda new at this and i've been browsing through the javascript exmaples but i couldn't find anything of the sort. anyway, given that i have a couple of different links, what i wanted to do was change the text content inside a specific layer depending on which link i click on. any help will be greatly appreciated! :)

gil davis
04-10-2003, 05:52 AM
<head>
<script>
var txt = new Array();
txt[0] = "This is the story of a boy named Ted";
txt[1] = "If his mother said, \"Ted! Be Good!\", he would";
txt[2] = "Momma don't worry, your Teddy boy's here";

function change(it) {
document.getElementById("d1").innerHTML = txt[it];
}
</script>
</head>
<body>
<table border>
<tr>
<td><a href="#" onclick="change(0);return false">Text 0</a><br>
<a href="#" onclick="change(1);return false">Text 1</a><br>
<a href="#" onclick="change(2);return false">Text 2</a></td>
<td id="d1" width=200></td>
</tr>
</table>
</body>

sherbhet
04-10-2003, 10:01 AM
hey gil! tnx for the code! i never really thought of doin it that way but all the same, it accomplished the same effect! that really helped! :D