I have a grails project where I need to select the fields that I want to delete, and when I press "delete", I need a function to delete all selected elements:
Html code:
<form name="bookForm" action="list" method="post"> .... <g:link controller="book" action="delete">Delete</g:link> .... .... <g:checkBox id="select_all" name="select_all" value="" onclick="selectAll();" /> .... <g:each in="${bookList}" status="i" var="bookInstance"> <tr class="${(i % 2) == 0 ? 'odd' : 'even'}"> <td><g:checkBox id="${bookInstance.id}" name="delete_checkbox" value="" /></td> </tr> </g:each> .... </form>
Javascript code:
<script type="text/javascript"> function selectAll(){//this function is used to check or uncheck all checkboxes var select = document.getElementById("select_all"); var checkboxes = document.forms['bookForm'].elements['delete_checkbox']; if (select.checked){ for (i = 0; i < checkboxes.length; i++) checkboxes[i].checked = true; }else{ for (i = 0; i < checkboxes.length; i++) checkboxes[i].checked = false; } }//this function works fine </script>
Problem:
I need an action to check all the checkboxes in the gsp list, and if they are checked, take their identifiers and delete the entry by id.
Can I do this using groovy or javascript?
user597987
source share