galvin Posted November 18, 2009 Share Posted November 18, 2009 Referring to the simple code below, if you have multiple Table Rows that you want to be hideable/showable, how can you adjust this code so that it only hides the same row in which you click the "hide" button. In other words, how do I alter the code so that when you click a "Hide" button, it will hide ONLY the Table Row to the immediate left of the Hide button that you clicked?... <html> <head> <script> function toggle() { if( document.getElementById("hidethis").style.display=='none' ){ document.getElementById("hidethis").style.display = ''; }else{ document.getElementById("hidethis").style.display = 'none'; } } </script> </head> <body> <table border="1"> <tr> <td>Always visible</td> </tr> <tr id="hidethis"> <td><textarea>Hide this</textarea><input onClick="toggle();" type='submit' value='hide' name='add'/></td> </tr> <tr id="hidethis"> <td><textarea>Hide this</textarea><input onClick="toggle();" type='submit' value='hide' name='add'/></td> </tr> <tr> <td>Always visible</td> </tr> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/182001-solved-handling-multiple-onclicks-to-showhide-a-table-row/ Share on other sites More sharing options...
premiso Posted November 18, 2009 Share Posted November 18, 2009 Not 100% sure but you need to give the row you want to hide unique id's... <tr id="hidethis1"> <td><textarea>Hide this</textarea><input onClick="toggle('hidethis1');" type='submit' value='hide' name='add'/></td> </tr> <tr id="hidethis2"> <td><textarea>Hide this</textarea><input onClick="toggle('hidethis2');" type='submit' value='hide' name='add'/></td> </tr> <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> That should do what you are wanting, you will just need to change each row's id to be unique and add it into the toggle function. There is probably a better way of doing it, but yea Link to comment https://forums.phpfreaks.com/topic/182001-solved-handling-multiple-onclicks-to-showhide-a-table-row/#findComment-959988 Share on other sites More sharing options...
galvin Posted November 18, 2009 Author Share Posted November 18, 2009 That'll work, thanks! Link to comment https://forums.phpfreaks.com/topic/182001-solved-handling-multiple-onclicks-to-showhide-a-table-row/#findComment-960004 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.