I got my answer.I just replaced getElementByName with getElementById var searchText = document.getElementById("search").value; Also whenever I typed the text I was pressing 'Enter' button instead of using onClick event. Use keys from request.form to get the form data. The problem was that I was passing an HTML element instead of its value, which is actually what I wanted to do (in fact in my php code I need that value as a foreign key for querying my Render an HTML template with a