File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

needed help on jsp + javascript

 
Kishore Dandu
Ranch Hand
Posts: 1934
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to populate a jsp parameter inside a java script function(this is invoked by onchange).
Is it really possible.
I tried,
<% String selectedDate =%> = document.form[0].<%=dateField%>.value;
It bombed on the run, saying can not convert void to string.
Is there another way I can do this.
Thanks,
Kishore.
 
Gabriel Fox
Ranch Hand
Posts: 170
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi U can call this function using the
onchange event handler :
function funName()
{
document.formName.nameOfFormElement.value=
"<%=referenceTofStringHoldingNewValue%>";
}
IF it's a drop down (select).U can use the selected property like this :
if(document.formName.nameOfFormElement.selected)
{
//Do Ur parameter assignment.
}
 
Brian Glodde
Ranch Hand
Posts: 171
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried to give Javascript a concrete variable reference rather than trying to dynamically generate that on the server side?

If you post in more detail, you'll receive more than enough pointers to solve the problem.
 
Kishore Dandu
Ranch Hand
Posts: 1934
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to retrieve information from a datastructure(resident in a java list) based on value entered in the form.
For the retrieve I need to initialize the variable in java to value from the form(in the onchange funtion).
Please tell me how I can do that.
thanks,
Kishore.
 
sylvia weller
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kishore,

I have to retrieve information from a datastructure (resident in a java list)
based on value entered in the form.

First, I would copy the java data structure into a JavaScript object when the jsp file gets loaded. (don't put it inside a js function, just inside the <SCRIPT> tags) For example, if the java data structure is an array:
<SCRIPT>
var arr = Array();
<%
String[] s = (String[])request.getAttribute("string array");
for(int i=0; i < s.length; ++i ) {
%>
arr[i] = '<% s[i]%>';
<% } %>
</SCRIPT>
Then, when the user does onChange, you pass a value to a js function which serves as an index into the js array.
As far as this goes
I need to initialize
the variable _in java_ to value from the form(in the onchange funtion).

I'm pretty sure you can't do this kind of assignment dynamically inside a javascript function. The js function is running purely on the clientside and has no dynamic access to java (serverside) stuff.
To update java values you need to _submit_ the html form with form values set. For example, if you're using purely jsp and your file is called "test.jsp", you can do <form action="test.jsp"> with <Input name="varx"> set to your computed value.
Then, when the form is submitted and "test.jsp" is loaded 'varx' is an input param and you can do an assignment something like this -

<% String selectedDate =%> = (String) request.getParameter("varx"); %>

Good luck.
Sylvia
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic