how to pass javascript value to jsp


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 10 of 10

Thread: how to pass javascript value to jsp

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Posts
    13

    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

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    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

  3. #3
    Join Date
    Sep 2005
    Posts
    13
    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

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    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

  5. #5
    Join Date
    Sep 2005
    Posts
    13
    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).

  6. #6
    Join Date
    Sep 2005
    Posts
    13
    Hi,

    can anyone help

  7. #7
    Join Date
    Oct 2004
    Posts
    311
    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.

  8. #8
    Join Date
    Sep 2005
    Posts
    13
    I cannot submit the form. is there anyway

  9. #9
    Join Date
    Oct 2004
    Posts
    311
    You could put an applet on the page, and have JavaScript communicate with the server through the applet

  10. #10
    Join Date
    Sep 2005
    Posts
    13
    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

  1. Replies: 2
    Last Post: 04-28-2005, 09:31 AM
  2. Replies: 3
    Last Post: 05-24-2001, 12:37 PM
  3. pass value to javascript in xsl
    By shailesh in forum XML
    Replies: 0
    Last Post: 02-27-2001, 02:37 PM
  4. JavaScript in JSP and servlets
    By satish in forum Java
    Replies: 4
    Last Post: 11-15-2000, 08:14 PM
  5. Sample Sites.
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center