Search code examples
grails

facing difficulty passing values from view to controller


I am using Grails, and a beginner. could somebody guide me through the following problem:

I want to pass the values in a select option along with an id to the controller from the view. I have tried using remoteFunction, createlink to pass the params through javascript but failed. Where am i going wrong?


Solution

    1. define select in gsp

      <g:select name="id" from="${1..5}" noSelection="['-1':'所有']" class="form-control" value="${selectedIds}"/>
      
    2. define change function in block

      <g:javascript>
          $("#id").change(function(){
              var id = $("#id").val();
              $.post("${request.contextPath}/formUrl",{id:id},function(data){
                  });
              });
      </g:javascript>