SaDman_SUT
SaDman_SUT

Reputation: 177

How to pass javascript variable to gsp tag

<script>
   var numx = 5000;
   alert('${myCustomTagLib(number:"numx")}')
</script>

How to pass javascript varable "numx" to gsp tag?

Upvotes: 0

Views: 1537

Answers (2)

Deepak
Deepak

Reputation: 2895

You cannot do like that way but you can do it with ajax

$.ajax({
   type: "POST",
   url: "/someController",
   data: { number: numx } // here  send the data to your controller and process it
})
.done(function( msg ) {
    // display the processed data here
    alert(  msg );
});

Upvotes: 1

Ashish Joseph
Ashish Joseph

Reputation: 1153

You clearly needs to understand, when GSP is executed and when JavaScript is executed.

Execution of GSP happens in the server. At this point, there is no JavaScript variable to assign. So your "numx" in always null, when "myCustomTagLib" is called.

Upvotes: 5

Related Questions