show and hide

S

student4lifer

I got the javascript show() to work on <td> but not on <tr>, once
I moved the <div> outside the <tr>, it stop working. What am I
missing? How would one fix this? Below is what I got. Thanks in
advance.

===========

<head>
<script type="text/javascript">
<!--
function show(id, checkbox) {
var visible = (checkbox.checked) ? "block" : "none";
document.getElementById(id).style.display = visible;
}

//-->
</script>
</head>

<table>
<tr>
<td></td>
<td>
<input name="car" value="T" type="checkbox"
onclick="show('div1', this)"> Car
</td>
</tr>
<div id="div1">
<tr>
<td>Make:
</td>
<td><input id="make" size="20"></td>
</tr>
<tr>
<td>Model:
</td>
<td><input id="model" size="20"></td>
</tr>
</div>
</table>
 
S

SAM

(e-mail address removed) a écrit :
I got the javascript show() to work on <td> but not on <tr>, once
I moved the <div> outside the <tr>, it stop working. What am I
missing? How would one fix this? Below is what I got. Thanks in
advance.

Nor TDs or TRs are "blocks"

foo.style.display = (foo.style.display=='')? 'none' : '';

Youre toggle cant work because you cant cut a table
(to insert some of its rows in a div, for instance)
===========

<head>

<script type="text/javascript">
function show(id, checkbox) {
var visible = (checkbox.checked)? "" : "none";
document.getElementById(id).style.display = visible;
}
</script>
</head>
<form>
<table>
<tr>
<td>
<input name="car" value="T" type="checkbox"
onclick="show('div1', this)"> Car
</td>
</tr>
<tr>
<td>
<table id="div1" style="display:none">
<tr>
<td>Make:</td>
<td><input id="make" size="20"></td>
</tr>
<tr>
<td>Model:</td>
<td><input id="model" size="20"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top