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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing text in a table

Status
Not open for further replies.

marduk813

Programmer
Jul 18, 2002
89
US
what i'm trying to do is create a simple q&a page that contains a table with 15 rows and 2 columns. each row in the first column contains a question, and the 1 cell in the second column (spanning 15 rows) is going to contain the answer. how can i make the text in the answer section change depending on which question is clicked on the left? i thought it could be done using targets and names, but i haven't been able to get that to work.

tia,
jas
 
You can do it with javascript like this:
<table>
<tr>
<td><a href=&quot;#&quot; onClick=&quot;window.document.getElementByID('the_answer').innerHTML='I am the answer for Q1';return false;&quot;>Q 1</a></td>
<td rowspan=&quot;15&quot; id=&quot;the_answer&quot;>&nbsp;</td>
</tr>
<tr>
<td>...</td>
</tr>
</table>

You could have also made the answer an iframe if you have long answers but this is more convenient for short ones. Remember to backslash your ' if you have any.

Rick
 
rick, thanks for the reply, but i have not been able to get your script to work. i've made the necessary changes to it to work on my page, but i get a script error on the page which reads &quot;object doesn't support this property or method&quot;.
also, the answers that will appear on the right side of the table will be several sentences long, some of them even longer and one may contain a small chart or table. i looked into possibly making a frame for it, but the whole faq takes place inside a frame already, and i didn't know how to create a frame inside a table cell. i've also toyed with the idea of just using images that contain the text for the answers. that would probably cover all my bases, but i wanted to avoid that route because of size issues.
 
nevermind. i got it to work with iframes. thank you very much for the suggestions. now all i have to do is figure out how to make the blank frame have a different colored background....
 
You can't set the background color for an iframe. You can make a blank page with a background color and set that to the default page.

Rick
 
The reason the innerHTML sample didn't work is that it contains a bug!

This works correctly...

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<html>
<head>
<title>Untitled</title>
<script>
function changeText() {
document.getElementById('the_answer').innerHTML = &quot;Text has changed!&quot;;
}
</script>
</head>

<body>
<form name=&quot;thisForm&quot; id=&quot;thisForm&quot;>
<table>
<tr>
<td id=&quot;the_answer&quot;>Original Text</td>
</tr>
<tr>
<td><a href=&quot;#&quot; onClick=&quot;changeText();&quot;>Change Text</a></td>
</tr>
</table>
</form>
</body>
</html>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top