daniel langer
daniel langer

Reputation: 1975

Pass Javascript Variable into createlink method call Grails

var search= document.getElementById('appMenu').value 
document.location.href= '${createLink(controller: 'application' , action:'ajaxAppSearch',   params: ['query': search])}'

The element appMenu is a text field, so I am getting the value that the user enters into the text box to pass into a search controller. However, it keeps telling me that the params query is null. It seems that search isn't being passed into the create link method. Anyone have a suggestion?

Upvotes: 7

Views: 7215

Answers (1)

Igor Artamonov
Igor Artamonov

Reputation: 35951

Grails (controllers, GSP and tags, etc) are working on server side. JavaScript on client side. And this link is prepared before sending data to browser, and before JavaScript can pass its variable into GSP tag.

But you can prepare base link on server side, and add extra parameter on client side, by using javascript, like:

var search= document.getElementById('appMenu').value;
document.location.href= '${createLink(controller: 'application' , action:'ajaxAppSearch')}?query=' + escape(search);

Upvotes: 14

Related Questions