Jump to content

Stupid Hide/Show Problem


DarkPrince2005

Recommended Posts

Why isn't any of my scripts working?

<html>
<head>
<script>
function toggle(which) {
if( document.getElementById(which).style.display=='none' ){
   document.getElementById(which).style.display = '';
}else{
   document.getElementById(which).style.display = 'none';
}
}
</script>
</head>
<body>


<form>
<table border="1">
<tr>
<td>Always visible</td>
</tr>
<tr id="hidethis1">
<td><textarea>Hide this1</textarea><input onClick="toggle('hidethis1');" type='submit' value='hide1' name='add'/></td>
</tr>
<tr id="hidethis2">
<td><textarea>Hide this2</textarea><input onClick="toggle('hidethis2');" type='submit' value='hide2' name='add'/></td>
</tr>
<tr>
<td>Always visible</td>
</tr>
</table>
</form>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/184110-stupid-hideshow-problem/
Share on other sites

your using type="submit" so it will submit the form, you should change that to type button or return false like the following hope it helps,

 

<html>
<head>
<script>
function toggle(which) {
if( document.getElementById(which).style.display=='none' ){
   document.getElementById(which).style.display = 'block';
}else{
   document.getElementById(which).style.display = 'none';
}
}
</script>
</head>
<body>


<form>
<table border="1">
<tr>
<td>Always visible</td>
</tr>
<tr id="hidethis1">
<td><textarea>Hide this1</textarea><input onClick="toggle('hidethis1');return false;" type='submit' value='hide1' name='add'/></td>
</tr>
<tr id="hidethis2">
<td><textarea>Hide this2</textarea><input onClick="toggle('hidethis2');return false;" type='submit' value='hide2' name='add'/></td>
</tr>
<tr>
<td>Always visible</td>
</tr>
</table>
</form>

</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.