Passing javascript variable to velocity variable templete

Hi everyone,
I have installed xwiki successfully and able to generate wiki pages using velocity templete language.
Could anyone please tell me that how can I pass javascript varible to velocity templete. I have gone through few forums that I need to pass the parameter to server to get this but I have no idea. Please find the files below. Thank you.

<script type="text/javascript">
function generateFunction()
{
  var variable = document.getElementById('text').value;
}
</script> 

#set($test = "variable")
$test

Hello,

Javascript is client side code and velocity server side, then I think that you must use ajax request to do it.
You can find an nice example here:

Pascal B