how to pass javascript value to jsp
Hi,
i would like to find how to pass/assign javascript value to jsp. I need to pass this value to javabean where I will retrieve the data based on the value selected by user in the html fom.
Pls help
TQ
[229 byte] By [
tllcll] at [2007-11-11 6:55:05]

# 1 Re: how to pass javascript value to jsp
Right off my head I'd say that this seems like a good case for hidden (form) field
values, set the values using javascript and pick them up as parameters in your
jsp code.
sjalle at 2007-11-11 22:40:01 >

# 2 Re: how to pass javascript value to jsp
Hi,
The form has many dependent fields, all these fields retrieve the data from the database based on the value of its previous field.
I can't submit form each time I select the data for each field. what is the other alternative
tllcll at 2007-11-11 22:41:01 >

# 3 Re: how to pass javascript value to jsp
That complicates it, as (stating the obvious:) the javascript runs on the client side and jsp on the server side.
If I understand you correctly you want to to database lookups while the user
selects/enters values in the form
I'm not big on beans so I would have used an applet that utilized an
HTTPConnection for "behind the scenes" data retrieval.
Javascript can call public methods in the applet and the applet can access
the web page elements and javascript code using the JSObject from the
netscape package, the so-called LiveConnect technology.
sjalle at 2007-11-11 22:42:05 >

# 4 Re: how to pass javascript value to jsp
I manage to select the data from the database for the 1st field and display on the listbox. Now the problem is, I am not sure how to get the value selected by the user (which is in javascript and use it in jsp). I need to use the value selected by the user to retrieve data from the database (which I will to call the bean file).
tllcll at 2007-11-11 22:43:05 >

# 5 Re: how to pass javascript value to jsp
Hi,
can anyone help
tllcll at 2007-11-11 22:44:03 >

# 6 Re: how to pass javascript value to jsp
Ok, here's a possible solution.
Have the Javascript write each value into a hidden field
then submit the form, you should be able to check if all the needed data is entered.
Each time you see a new piece of data come in, you know where you are in the flow of the page, so you know what to do serverside.
When all the parameters have been entered, you can do the actual work you need to do.
Just setup a nice fat if/else statement serverside to diferentiate between the various parameters:
if (request.getParameter("param1") != null &&
request.getParameter("param2") == null) {
//do something
} else if (request.getParameter("param1") != null &&
request.getParameter("param2") != null) {
//do something
}
This example is easily extended for more parameters.
ractoc at 2007-11-11 22:45:07 >

# 7 Re: how to pass javascript value to jsp
I cannot submit the form. is there anyway
tllcll at 2007-11-11 22:46:05 >

# 8 Re: how to pass javascript value to jsp
You could put an applet on the page, and have JavaScript communicate with the server through the applet
ractoc at 2007-11-11 22:47:02 >

# 9 Re: how to pass javascript value to jsp
can i use iframe, if so how to apply to the following codes
Thanks in advance
Part of the code for ref - trans_main.jsp
------------
<%@page import="java.util.List.*;"%>
<jsp:useBean id = "trx" class="trx.TransDetails" />
<%
String jCompany;
ArrayList listCompany = new ArrayList();
int sizeCompany=0;
%>
<html>
<head><title>JSP Page</title></head>
<title>Form</title>
<body>
<form name="transaction" method="post" >
<input type="hidden" name="hid_page" value="main"/>
<table>
<th width="9%"align="left">Company</th>
<td width="1%" align="center">:</td><td width="5%" >
<select name="co_no" id="co_no" >
<option value="select"></option>
<%
listCompany = trx.display_company();;
ListIterator iter = listCompany.listIterator();
while (iter.hasNext()) {
jCompany =(String)iter.next();
%>
<option value="<%=jCompany %>"><%=jCompany %></option>
<% } %>
</select>
</td>
</tr>
<tr>
<th width="9%"align="left">Project</th>
<td width="1%" align="center">:</td><td width="25%">
<select name="proj_cde" >
<option value="select"></option>
--
</select>
</td>
</tr>
</table>
</form>
</body>
</html>
tllcll at 2007-11-11 22:48:11 >

