File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes needed help on jsp + javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "needed help on jsp + javascript" Watch "needed help on jsp + javascript" New topic
Author

needed help on jsp + javascript

Kishore Dandu
Ranch Hand

Joined: Jul 10, 2001
Posts: 1934
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.


Kishore
SCJP, blog
Gabriel Fox
Ranch Hand

Joined: Oct 17, 2001
Posts: 170
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

Joined: Jun 27, 2001
Posts: 171
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

Joined: Jul 10, 2001
Posts: 1934
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

Joined: Jan 07, 2002
Posts: 29
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
 
subject: needed help on jsp + javascript
 
Similar Threads
Having some multidimensional array problem in JSP
Passing runtime variables to jsp 2.0 tag files.
JSP error: invalid arguments in call . PLEASE HELP
how to iterate a arraylist and print values in table using logic:iterate
JSTL Get value from HashMap inside HashMap