Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-06-2012, 08:46 PM   PM User | #1
naveendk.55
New Coder

 
Join Date: Aug 2011
Posts: 88
Thanks: 5
Thanked 0 Times in 0 Posts
naveendk.55 is an unknown quantity at this point
Question Make multiselect dropdown selected

UPDATED code that I tried and excepted result from here. Tried my best to explain it again in brief.


I have multiSelect drop down on my web page designed in JSP. End user will select required options and save the form to Database. Below is the original Dropdown that gets values and index from Database Master Table. Selected values are saved in another table.

Original Dropdown on the page.

PHP Code:
<table>
 <
tr>
 <
tdDepartments Impacted   </td>
    <
td><select multiple="multiple" name="abc" id="abc">
     <%

         
Statement stt3 conn.createStatement();
         
ResultSet rstt3 stt3.executeQuery("SELECT DEPT_DEPARTMENT_ID, DEPT_NAME FROM [PA].[dbo].[PA_DEPT_DEPARTMENT] ORDER BY DEPT_NAME ASC");
         while (
rstt3.next()) {

         %>

         <
option value="<%=rstt3.getString(1)%>"><%=rstt3.getString(2)%>
         </
option>
         <%
             }
            
stt3.close();
     
rstt3.close();
                            %>
    </
select></td>  </tr> </table
Below code retrieve saved database values and display them as selected in new select tag. However, I want the selected values to be show in above table instead of new Dropdown.


PHP Code:
<%
 
ArrayList al = new ArrayList();    
 
String dept null;
 
String deptID "SELECT DEPARTMENT_ID FROM  [PA_RD_DEP_REQ_DETAILS_DEPARTMENT_MAP] inner join  [PA_RD_REQUISITION_DETAILS] on RD_DEP_RD_ID=RD_ID where RD_ID=?";

         
PreparedStatement pst4 conn.prepareStatement(deptID);
         
pst4.setString(1RD_ID);
         
ResultSet rstt1 pst4.executeQuery();
         while (
rstt1.next()) {
             
dept=rstt1.getString(1);
            
al.add(dept);

         }
         for(
int i=0i<al.size(); i++)
         {
         
String deptName "SELECT [DEPT_NAME] FROM  [PA_DEPT_DEPARTMENT] WHERE [DEPT_DEPARTMENT_ID]=?";
         
PreparedStatement pst5 conn.prepareStatement(deptName);
         
pst5.setString(1, (String)al.get(i));
         
ResultSet rstt5 pst5.executeQuery();
         while (
rstt5.next()) {
             %>
             <
option value="<%=(String)al.get(i)%>" selected="selected"><%=rstt5.getString(1)%>
             <%  


         }
         }


         %> 

Last edited by naveendk.55; 11-07-2012 at 07:27 AM.. Reason: Updated description and code
naveendk.55 is offline   Reply With Quote
Reply

Bookmarks

Tags
java, jsp

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:14 PM.


Advertisement
Log in to turn off these ads.