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
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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.