Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 809
daniel langer Avatar asked Jun 14 '12 16:06

daniel langer


1 Answers

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);
like image 164
Igor Artamonov Avatar answered Sep 21 '22 15:09

Igor Artamonov