Server-side vs Client-side
In order to allow your server to respond to user input there has to be a request sent. You can ask your server can send to send a response in one of two ways:
- A completely new page - such as when a link is clicked and a new HTML page loaded
- A AJAX response - run asynchronously and formatted however you want so that your client side JavaScript can use it.
But the server cannot manipulate the DOM of your existing page by itself. Even with AJAX, it has to have some code (usually JavaScript) on the client side to manipulate the page.
Normally if you are doing a search, I would recommend option 1. This has the benefit of being simpler and it allows your users to navigate back/forwards or bookmark their search (assuming you make a GET call vs POST). See When to Use AJAX and When Not To
Using AJAX
If you want to use AJAX, make a call to your server create your xmlhttp object and then then you can pass your variable as @A4L mentioned only using AJAX. It would look something like this:
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
// Do what you want with the results from your server
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET",'myJSP.jsp/?id=' + id,true);
xmlhttp.send();
Then your server can pull in the parameter like @A4L mentioned. You may want to have your response just be straight text or an HTML block that the javascript can place inside a DIV but that's all up to you.
Disclaimer: I'm no expert in AJAX. Most of this is something you can learn from the W3 Schools site