473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to Keep selected value and Fetched value in same dropdownbox in jsp???

1
i ve fetched value from database and show them in dropdown box after i select the value from dropdown i submit tht value by using this.form.submit(). thn finally the dropdown box show the selected value.. but i want to show the selected value and the fetched value also.. anyone help me...





Here is my Code

Expand|Select|Wrap|Line Numbers
  1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  2.     pageEncoding="ISO-8859-1"%>
  3.             <%@ page import="java.sql.*" %>
  4.         <%@page import="java.util.Date"%>
  5.                 <%@ page import="java.math.*" %>
  6.  
  7. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  8. <html>
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  11. <title>Insert title here</title>
  12. </head><h3>Invoice Details</h3>
  13. <body>
  14. <%
  15. String name=request.getParameter("bname");
  16. //System.out.println("name"+name);
  17. String size=request.getParameter("bsize");
  18. //System.out.println("size"+size);
  19. String qty=request.getParameter("quantity");;
  20. Date date=new Date();
  21.  
  22. String availablequantity=(String)request.getAttribute("quantity");
  23. //System.out.println("quantity"+availablequantity);
  24. String invoice=request.getParameter("invoice");
  25.  
  26. String newqty=(String)request.getAttribute("up1");
  27. //System.out.println(invoice);
  28. try{
  29.  
  30.     Class.forName("org.postgresql.Driver");
  31.     Connection con=DriverManager.getConnection("jdbc:postgresql://192.168.1.2:5432/tlsagencies","ihisblank","ihisblank");
  32.     Statement s1=con.createStatement();
  33.     Statement s2=con.createStatement();
  34.     Statement s3=con.createStatement();
  35.     Statement s4=con.createStatement();
  36.     Statement s5=con.createStatement();
  37.     Statement s6=con.createStatement();
  38.     Statement s7=con.createStatement();
  39.     Statement s8=con.createStatement();
  40.     Statement s9=con.createStatement();
  41.     Statement s10=con.createStatement();
  42.     Statement s11=con.createStatement();
  43.  
  44.  
  45.  
  46.  
  47.     String x="Select Size";
  48.     //System.out.println("qwadsasdasd"+x);
  49.  
  50.     ResultSet r1=s1.executeQuery("select brandname from brandlist");
  51.     %>
  52. <form action="Table.jsp" method="get"><table><div><tr><td>BrandName:</td><td><select name="bname" onchange="this.form.submit()" id="bname">
  53. <%if(name!=null)
  54. {
  55. %>
  56. <option value="<%=name %>"><%=name %></option>
  57. <%
  58. }
  59. %>
  60. <%if(name==null)
  61.     {%>
  62.     <option value="0">Select Brand</option>
  63.     <%
  64.     while(r1.next())
  65.     {
  66.  
  67.     %>
  68. <option value="<%=r1.getString("brandname") %>"><%=r1.getString("brandname") %></option>
  69. <%
  70. }
  71.     }
  72.     %>
  73.  
  74. </select></td></tr></div>
  75. <div><tr><td>BrandSize:</td><td><select name="bsize" onchange="this.form.submit()" id="bsize">
  76. <% if((size!=null)&&(name!=null))
  77. {
  78. %>
  79. <option value="<%=size %>"><%=size %></option>
  80. <% 
  81. }
  82.  
  83.  
  84.  if((size==null)||(name!=null))
  85.  {
  86.  
  87.     ResultSet r2=s2.executeQuery("select brandlist_seq from brandlist where brandname='"+name+"'");
  88.     if(size==null){
  89.     %>
  90. <option name="0">Select Size</option>
  91.                         <%
  92.     }
  93.     while(r2.next())
  94.     {
  95.         request.setAttribute("bseq", r2.getString("brandlist_seq"));
  96.  
  97.         ResultSet r3=s3.executeQuery("select sizelist_seq from stockdtl where brandlist_seq='"+r2.getString("brandlist_seq")+"'");
  98.         while(r3.next())
  99.         {
  100.             request.setAttribute("sizeseq", r3.getString("sizelist_seq"));
  101.             ResultSet r4=s4.executeQuery("select brandsize from sizelist where sizelist_seq='"+r3.getString("sizelist_seq")+"'");
  102.  
  103.             while(r4.next())
  104.             {
  105.                 String bsize=r4.getString("brandsize");
  106.     //    request.setAttribute("brandsize", bsize);
  107.                 %>
  108.                 <option value="<%=bsize %>"><%=bsize %></option>
  109.             <%}
  110.             }
  111.             }
  112.             }
  113.             %>
  114. </select></td></tr></div>
  115. <%if((size==null)||(size.equals(x)))
  116. {
  117.     %>
  118.     <div><tr><td>Available Quantity:</td><td><input type="text" name="quantity" value="<%=qty%>" id="quantity" readonly></td></tr></div>
  119.     <%
  120.  
  121. }
  122.  
  123. else
  124. {
  125. ResultSet r5=s5.executeQuery("select brandlist_seq from brandlist where brandname='"+name+"'");
  126. while(r5.next())
  127. {
  128.     request.setAttribute("bseq", r5.getString("brandlist_seq"));
  129. }
  130. ResultSet r6=s6.executeQuery("select sizelist_seq from sizelist where brandsize='"+size+"'");
  131. while(r6.next())
  132. {
  133.     request.setAttribute("sseq", r6.getString("sizelist_seq"));
  134. }
  135. String brandseq=(String)request.getAttribute("bseq");
  136. String sizeseq=(String)request.getAttribute("sseq");
  137.  
  138. //System.out.println(brandseq);
  139. //System.out.println(sizeseq);
  140. ResultSet r7=s7.executeQuery("select quantity from stockdtl where brandlist_seq='"+brandseq+"' and sizelist_seq='"+sizeseq+"'");
  141. while(r7.next())
  142. {
  143.     String availablequantity1=r7.getString("quantity");
  144.     //System.out.println(availablequantity1);
  145.  
  146.     request.setAttribute("quantity", r7.getString("quantity"));
  147.  
  148.     %>
  149.  
  150. <div><tr><td>Available Quantity:</td><td><input type="text" name="quantity" value="<%=availablequantity1%>" id="quantity" readonly></td></tr></div>
  151. <%}
  152.  
  153. }
  154.  
  155. %>
  156. <div><tr><td>Invoice Quantity:</td><td><input type="text" name="invoice"></td></tr></div>
  157. <tr><td></td><td><input type="submit" value="submit"></td></tr>
  158. </table></form>
  159. <%if((invoice!=null)&&(invoice!=""))
  160.     {
  161. String brandseq=(String)request.getAttribute("bseq");
  162. String sizeseq=(String)request.getAttribute("sseq");
  163. //System.out.println(brandseq);
  164. //System.out.println(sizeseq);
  165. ResultSet r=s11.executeQuery("select quantity from stockdtl where brandlist_seq='"+brandseq+"' and sizelist_seq='"+sizeseq+"'");
  166. while(r.next())
  167. {
  168.     String quant=r.getString("quantity");
  169.     request.setAttribute("quantity", quant);
  170. }
  171. String qq=(String)request.getAttribute("quantity");
  172. //System.out.println("new"+qq);
  173.  
  174.  
  175.     ResultSet r8=s8.executeQuery("select stock_seq from stockdtl where brandlist_seq='"+brandseq+"' and sizelist_seq='"+sizeseq+"'");
  176.     while(r8.next())
  177.     {
  178.         int is=s9.executeUpdate("INSERT INTO invoicedtl(stock_seq, created_date, invoice_qty)  VALUES ('"+r8.getString("stock_seq")+"','"+date+"','"+invoice+"');");
  179.  
  180.     }
  181.     //int update=((Integer.parseInt)availablequantity)-((Integer.parseInt)invoice);
  182. //    Integer.valueOf(availablequantity)-(Integer.valueOf(invoice));
  183.  
  184. int qt=Integer.parseInt(qq);
  185.  
  186. //System.out.println("qty"+availablequantity);
  187. int in=Integer.parseInt(invoice);
  188. int newqt=qt-in;
  189. //System.out.println(newqt);
  190. String updatedquantity=Integer.toString(newqt);
  191. request.setAttribute("up1", updatedquantity);
  192.  
  193.  
  194. //System.out.println(updatedquantity);
  195.  
  196.  
  197. //    int iss=s10.executeUpdate("UPDATE stockdtl  SET quantity='"+updatedquantity+"'   WHERE brandlist_seq='"+brandseq+"' and sizelist_seq='"+sizeseq+"';");
  198.  
  199.  
  200.     }
  201.  
  202.     %>
  203.  
  204.  
  205.  
  206.  
  207. <%
  208. }
  209. catch(Exception e)
  210. {
  211. }%>
  212.  
  213.  
  214. </body>
  215. </html>
Attached Files
File Type: txt new.txt (6.1 KB, 255 views)
Jun 12 '15 #1
1 1319
chaarmann
785 Expert 512MB
I do not understand. How can you show "fetched" value (whatever that is) and selected value? You can only show one value! If you want to show two values at the same time, then you need a list and not a dropdown box!
Like that:
Expand|Select|Wrap|Line Numbers
  1. <select multiple>
  2.   <option selected>entry1</option>
  3.   <option>entry2</option>
  4.   <option selected>entry3</option>
  5.   <option>entry4</option>
  6. </select>
Jun 15 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Lisa | last post by:
I have a drop down that defaults to "select" after the page refreshes. How do I keep the selected value in the dropdown field... I've tried EVERYTHING and nothing works! :( <script...
2
by: Patrick | last post by:
Hello, I have a drop down list that when a value is selected the page refreshes itself but the selected value changes back to the default value. I would like to keep the selected value after the...
4
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item,...
2
by: Joey | last post by:
Hi There, I am trying to get the selected value of a listbox when I click a button, everything works ok and I can bind the list and when I have a basic page and click a button to invoke a sub it...
1
by: CorporateCoder | last post by:
Hi, I am trying to bind the selected value of a databound dropdown box in a databound gridview control to the value being displayed in the template column the dropdown box has been added to. ...
2
by: yasodhai | last post by:
Hi, I used a dropdown control bind to a datagrid. <EditItemTemplate> <asp:DropDownList ID="FldType_edit" Runat="server" DataSource='< %#GetFieldType()%>' DataTextField="Type" />...
16
by: tarunkhatri | last post by:
Hi. I have a javascript function to change the value of the cell on chnage event of a dropdown list.My code is workin but the problem is that the value of the cell is chaning but not respective to...
1
by: polluxsoftech | last post by:
HI, I have 1 listbox named lbCountry i have inserted each selected value from listbox into database by following code: For iLoop = 0 To lbCountry.Items.Count - 1 ' item selected Dim i...
0
by: ahmedelbahar66 | last post by:
how to use view state to keep selected value of dropdownlist in user control displayed in masterpage. when postback occur thae selected value of dropdownlist is cleared i dont know the reason !
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.