Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using JavaScript within JSP  RSS feed

 
igwe kalu kalu ogba
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have a jsp page, in this page I have declared a method lets call it writeToFile. Now I have also created a series of inputs (html) that contain or can contain data. What I am trying to do is to create a scenario where the writeToFile method in my jsp page can take data from the input tags available on the page. ie. the contents of the input tags can be used in the writeToFile method. Is this possible? and if so , how do I go about it.
 
lekha phijo
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this method is a javascript method use text.value to retrive the value of the controls.

onsubmit invoke this method!!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming "writeToFile" is written in JavaScript (so you intend it be processed clientside), each form element in your HTML has attributes you can access to get their value. An <input type="text" /> element for example has a "value" property which equals whatever its value is. You can process this value at any time, presuming a suitable event has happened to fire your JavaScript function. lekha phijo gives you one choice, there are a whole bunch available (see here - being aware some of these will be IE only).

Given the name of your possibly-JavaScript function, I probably should warn you that you cannot write to a file using JavaScript.

If writeToFile is a method written in Java and to be run serverside, then you just need to process the contents of the request as you would any value passed as the result of a form submission.
[ July 05, 2005: Message edited by: Paul Sturrock ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!