-
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
-
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.
eschew obfuscation
-
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
-
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.
eschew obfuscation
-
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).
-
-
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:
Code:
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.
-
I cannot submit the form. is there anyway
-
You could put an applet on the page, and have JavaScript communicate with the server through the applet
-
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>
Similar Threads
-
By Serpent330 in forum Web
Replies: 2
Last Post: 04-28-2005, 09:31 AM
-
Replies: 3
Last Post: 05-24-2001, 12:37 PM
-
Replies: 0
Last Post: 02-27-2001, 02:37 PM
-
Replies: 4
Last Post: 11-15-2000, 08:14 PM
-
By Murray Foxcroft in forum Web
Replies: 5
Last Post: 11-02-2000, 02:42 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks