Controlling table content with links

reidy
reidy used Ask the Experts™
on
Hello

Is it possible to control the contents of a table within an html page with links and if so how?. I know you can control frame content but I wanted to change the information within a particular table when the viewing clicks on a menu link.

Thanks

Reidy

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Use a div inside the table. Here is a sample code.

<html>
<head>
<SCRIPT language="javascript">
function swapText(obj) {    
obj.innerHTML = "Dynamic Content";
}    
</SCRIPT>
</head>
<body>
<table><tr><td>
<div id="dynCont">
Initial Text
</div>
</td></tr></table>

<a href=# onClick="javascript:swapText(dynCont)">Try Me!</a>
</body>
</html>
Commented:
I think you need the quotes:

<html>
<head>
<SCRIPT language="javascript">
<!--
function swapText(obj) {    
document.getElementById(obj).innerHTML = "Dynamic Content";
}    
// -->
</SCRIPT>
</head>
<body>
<table><tr><td>
<div id="dynCont">
Initial Text
</div>
</td></tr></table>

<a href="javascript://" onClick="swapText('dynCont')">Try Me!</a>
</body>
</html>

Commented:
We are not passing a string, it is an object variable.
Putting quotes to it will change it to a string, i guess.
note that our javascript codes are differend and I use an object while you use the object name.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Author

Commented:
Hello fozylet and apprenti

Thanks I got both of your scripts working ok but I can't seem to get the text to appear over multiply lines, basically I wanted to have scrollable text paragraphs within the table or even several images. I don't know if this is possible as I' new to html and javascript.

Commented:
Have you tried moz.

Commented:
...My copy of moz does not run fozylet's.

Commented:
"Dynamic<br> Content"
+"More dynamic<br>Content"

Commented:
did not try moz... tested only on IE
getElementById is the recommended way to go, i think

Author

Commented:
yes I agree with the comment from mplungjan with regards to splitting the points
Michel PlungjanIT Expert
Top Expert 2009

Commented:
So feel free to do it...
Please click split points above the entry field and follow instructions

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial