gangsterwanster1 Posted May 13, 2009 Share Posted May 13, 2009 So i have a table with a lot of rows. I want the user to decide if he or she should keep the rows so in 5th column i added a checkbox. Is there anyway to do it so if the check box value is checked then delete that row? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 Add an onclick to the checkbox. Quote Link to comment Share on other sites More sharing options...
Axeia Posted May 13, 2009 Share Posted May 13, 2009 I'd use an onChange (so it works for keyboard navigation as well) Errr this might work: <input type="checkbox" onchange="removeRow( this );" /> function removeRow( chk ) { // <tr> <table> var i = chk.parentNode.parentNode.rowIndex; chk.parentNode.parentNode.deleteRow(i); } adding onchange( this ) Quote Link to comment Share on other sites More sharing options...
AmandaF Posted May 14, 2009 Share Posted May 14, 2009 I'd use an onChange (so it works for keyboard navigation as well) Most (all?) browsers interpret onclick as hitting enter while tabbed onto an element in addition to clicking the mouse, so onclick and onchange are equally accessible in this situation. It's just with onmouseover and other mouse-specific functions that you need to include a keyboard equivalent. But other than that, yeah, what Axeia said. Quote Link to comment Share on other sites More sharing options...
gangsterwanster1 Posted May 17, 2009 Author Share Posted May 17, 2009 will you please post an example on this? (I cant get it to work) Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 17, 2009 Share Posted May 17, 2009 Can you post your code? Quote Link to comment Share on other sites More sharing options...
Axeia Posted May 17, 2009 Share Posted May 17, 2009 I'd use an onChange (so it works for keyboard navigation as well) Most (all?) browsers interpret onclick as hitting enter while tabbed onto an element in addition to clicking the mouse, so onclick and onchange are equally accessible in this situation. It's just with onmouseover and other mouse-specific functions that you need to include a keyboard equivalent. Don't ask me for a source but I remember some mobile browser not doing so. But really you want to change it when the value chances, so using onchange makes the most Sense. This example works in both Firefox and Konqueror: <html> <head> </head> <body> <table border="1"> <tr> <td>Remove me</td> <td><input type="checkbox" onchange="removeRow( this )" /></td> </tr> <tr> <td>Or me</td> <td><input type="checkbox" onchange="removeRow( this )" /></td> </tr> </table> <script type="text/javascript"> function removeRow( chk ) { // <tr> <table> <dunno> <tbody> var i = chk.parentNode.parentNode.rowIndex; chk.parentNode.parentNode.parentNode.parentNode.deleteRow(i); } </script> </body> </html> Seems like there's some more nodes to move up to just use and alert instead of deleterow alert(chk.parentNode.parentNode) and keep adding .parentnode behind it till it alerts you with a tablecell, then use that to do the deleteRow on. (Or give the table an ID and then do Document.getElementById( 'tableId' ).deleteRow(i); Which is probably a better approach as both Konqueror and Firefox seem to be adding a <tbody> and another mysterous element.. and I'm not sure as to how other browsers handle it.. so it might results in having to move up a different amount of parentnodes. Quote Link to comment Share on other sites More sharing options...
gangsterwanster1 Posted May 17, 2009 Author Share Posted May 17, 2009 Thanks, one more question though. Is there any way to permanently delete the row? Because you can delete the row by checking it but then when you refresh the page everything is back. Quote Link to comment Share on other sites More sharing options...
Axeia Posted May 17, 2009 Share Posted May 17, 2009 You could use a cookie to delete it again on the next pageload, but permanently.. no. Unless this is somewhere where users are logged in, in which case you can use Ajax (store the setting on the server) Quote Link to comment Share on other sites More sharing options...
gangsterwanster1 Posted May 17, 2009 Author Share Posted May 17, 2009 You could use a cookie to delete it again on the next pageload, but permanently.. no. Unless this is somewhere where users are logged in, in which case you can use Ajax (store the setting on the server) is there a way to store data without using sql database? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 17, 2009 Share Posted May 17, 2009 is there a way to store data without using sql database? Yeah. You'll need some way of keep track of who deleted what. Quote Link to comment Share on other sites More sharing options...
gangsterwanster1 Posted May 17, 2009 Author Share Posted May 17, 2009 is there a way to store data without using sql database? Yeah. You'll need some way of keep track of who deleted what. any suggestions on how to do this? Quote Link to comment Share on other sites More sharing options...
AmandaF Posted May 18, 2009 Share Posted May 18, 2009 Don't ask me for a source but I remember some mobile browser not doing so. Thanks, good to know. I seriously need to learn more about mobile browsers. Gangster, do you want the changes to affect everyone who views the site, or just that specific person? You can set a cookie if you only want the changes to be visible to that person. Otherwise you're going to need either a database or a file or something on the server that keeps track of what's been changed. If you really don't want to use sql, you can always write the changes out to a text file. (Read this for more info: http://www.tuxradar.com/practicalphp/8/0/0) For security purposes, though, it really would be better to use a database. 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.