• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Settiing session attribute value in first page

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic