DarkPrince2005 Posted December 5, 2009 Share Posted December 5, 2009 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> Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 5, 2009 Share Posted December 5, 2009 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.