title: Is there a way to call a controller action from a javascript function?
body: <p>I have a grails project I need to select the fields that I want to delete and when I click delete, I need a function to delete all selected items:</p>
  
  <p><b>html code:</b></p>
  
  <pre><code>&lt;form name="bookForm" action="list" method="post"&gt;
      ....
      &lt;a onclick="deleteBooks();"&gt;Delete&lt;/a&gt;
      ....
      ....
      &lt;g:checkBox id="select_all" name="select_all" value="" onclick="selectAll();" /&gt;
      ....
      &lt;g:each in="${bookList}" status="i" var="bookInstance"&gt;
          &lt;tr class="${(i % 2) == 0 ? 'odd' : 'even'}"&gt;
              &lt;td&gt;&lt;g:checkBox id="${bookInstance.id}" name="delete_checkbox" value="" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/g:each&gt;
      ....
  &lt;/form&gt;
  </code></pre>
  
  <p><b>javascript code:</b></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function selectAll(){
          var select = document.getElementById("select_all");
          var checkboxes = document.forms['bookForm'].elements['delete_checkbox'];
          if (select.checked){
              for (i = 0; i &lt; checkboxes.length; i++) checkboxes[i].checked = true;
          }else{
              for (i = 0; i &lt; checkboxes.length; i++) checkboxes[i].checked = false;
          }
      }
  
      function deleteBooks(){
          var checkboxes = document.forms['bookForm'].elements['delete_checkbox'];
          var counter = 0;
              for (i = 0; i &lt; checkboxes.length; i++){
                  if(checkboxes[i].checked){
                      counter ++;
                      ${g.remoteFunction(action:'delete', controller:'book', id:checkboxes[i].id) }
                  }
              }
              if (counter == 0) alert("select books to delete");
          }
      &lt;/script&gt;
  </code></pre>
  
  <p>selectAll function works fine, but deleteBooks function cause this error when i add 
  <code>${g.remoteFunction(action:'delete', controller:'book', id:checkboxes[i].id) }</code></p>
  
  <p><b>Exception:</b></p>
  
  <pre><code>Error 500: Error evaluating expression [g.remoteFunction(action:&amp;#39;delete&amp;#39;, controller:&amp;#39;book&amp;#39;, id: checkboxes[i].id)] on line [26]: Cannot get property &amp;#39;null&amp;#39; on null object
  Servlet: grails
  URI: /myProject/grails/book/list.dispatch
  Exception Message: Cannot get property &amp;#39;null&amp;#39; on null object 
  Caused by: Error evaluating expression [g.remoteFunction(action:&amp;#39;delete&amp;#39;, controller:&amp;#39;book&amp;#39;, id: checkboxes[i].id)] on line [26]: Cannot get property &amp;#39;null&amp;#39; on null object 
  Class: list.gsp 
  At Line: [26] 
  Code Snippet:
  </code></pre>
  
  <p>and if I substitute it with <code>${g.remoteFunction(action:'delete', controller:'book') }</code></p>
  
  <p><b>Exception:</b></p>
  
  <pre><code>Error 500: Error evaluating expression [g.remoteFunction(action:&amp;#39;delete&amp;#39;, controller:&amp;#39;book&amp;#39;)] on line [27]: No javascript provider is configured
  Servlet: grails
  URI: /myProject/grails/book/list.dispatch
  Exception Message: No javascript provider is configured 
  Caused by: Error evaluating expression [g.remoteFunction(action:&amp;#39;delete&amp;#39;, controller:&amp;#39;book&amp;#39;)] on line [27]: No javascript provider is configured 
  Class: list.gsp 
  At Line: [27] 
  Code Snippet:
  </code></pre>
  
  <p><b>How can I call a controller action from a javascript function or jquery?</b></p>