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
What is the value of the following expression?
Math.round(Math.random() + 2.50001);
A) 2
B) 3
C) It is impossible to say
Math.random() returns a double greater than or equal to 0.0 and less than 1.0. Math.random() + 2.50001 is a double greater than 2.5 and less than 3.5. Math.round() of any number between but not including 2.5 and 3.5 is 3.
...Java Math.round() which by the way returns long...