Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing text

Status
Not open for further replies.

IainT

MIS
Nov 21, 2003
15
GB
Hiya,

Am v bad at javascript but am trying to use javascript to try to do something on a web page. Any help would be appreciated.

Basically, if I have some HTML code along the lines of

<html>
<head>
<title>1</title>
</head>
<body bgcolor=&quot;#FFFFFF&quot;>
<table width=&quot;90%&quot; border=&quot;0&quot; align=&quot;center&quot;>
<tr>
<td> </td>
<td>link1</td>
</tr>
<tr>
<td>text</td>
<td>link2</td>
</tr>
<tr>
<td> </td>
<td>link3</td>
</tr>
</table>
</body>
</html>

I want to make it so that when someone clicks on &quot;link1&quot; the bit where it says &quot;text&quot; changes to, say, &quot;example1&quot;

And when someone then clicks on &quot;link2&quot;, I want &quot;example1&quot; to change to &quot;example2&quot;. And so on.

Is this possible using Javascript?

Many thanks

Iain
 
You'd have to use Dynamic HTML to do this, and have different code for Nestscape than IE. IE would use a DIV with the text in it, while Netscape would use a LAYER with the text in it. You can't do it in plain HTML and Javascript, though, without reloading the page and passing parameters in the URL.
 
Copy/paste and see if this is what yo need:

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
function changeText()
{
mybody=document.getElementsByTagName(&quot;body&quot;).item(0);
mytable=mybody.getElementsByTagName(&quot;table&quot;).item(0);
mytablebody=mytable.getElementsByTagName(&quot;tbody&quot;).item(0);
myrow=mytablebody.getElementsByTagName(&quot;tr&quot;).item(1);
mycel=myrow.getElementsByTagName(&quot;td&quot;).item( 0 );
mycelltext = mycel.childNodes.item( 0 ).data;
newNode = document.createTextNode(&quot;Example 1 &quot;);


mybody.appendChild( newNode );

alert( mycelltext );

}
//-->
</SCRIPT>
</HEAD>

<BODY>
<html>
<head>
<title>1</title>
</head>
<body bgcolor=&quot;#FFFFFF&quot;>
<table width=&quot;90%&quot; border=&quot;0&quot; align=&quot;center&quot;>
<tbody>
<tr>
<td> </td>
<td><a href=&quot; onmouseover=&quot;changeText();&quot;>Link1</a></td>
</tr>
<tr>
<td>text</td>
<td><a href=&quot;</tr>
<tr>
<td> </td>
<td><a href=&quot;</tr>
</tbody>
</table>
</body>
</html>
 
The getElements functions won't work in Netscape 4, which is still far more popular than Netscape 6.x
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top