Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Settiing session attribute value in first page  RSS feed

John Vergis
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to set a form element value in the session in the javascript function.

I have a search form where the user enters the search element name say 'xyz'

form ........

<font size="4">Enter the Name: </font>
<input name="EmpName" type="text">

<input type="submit" name="Submit" value="Search" onClik="return checkInput(this.form)" >


On submission of the form the javascript function checkInput() is called to check the validity of the form input element .

In the javascript function, once the value is validated, then i would like to set the validated input in the session..

How can i set this value in the session.

function checkInput(theForm){

var empNameVal=theForm.EmpName.value;

if (!isBlank(empNameVal)) {
var trimmedVal = Trim(empNameVal);




return true;
alert('Please enter atleast 1 non-whitespace characters for your search.');
return false;

return true;

in the line session.setAttribute("searchname",....); I would like to set the trimmedVal as the value for searchname. Could you let me know how to do this.

Bear Bibeault
Author and ninkuma
Posts: 66143
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't do it that way.

The embedded Java in yout Javascript function has executed when the page was being formed to send to the browser, long before the user even saw the form on the page. The only way you can interact with the server is via the form submission.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!