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)" >

</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);

theForm.EmpName.value=trimmedVal;

<%

session.setAttribute("searchname",....);

%>
theForm.submit();
return true;
}
else{
alert('Please enter atleast 1 non-whitespace characters for your search.');
theForm.EmpName.focus();
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.


Thanks
John
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
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!