?
Solved

Drop down box query

Posted on 2004-11-11
7
Medium Priority
?
172 Views
Last Modified: 2011-09-20
Hi
Iam retreving certain results from database and displaying them in a JSP page.Against each record there is a drop down box which contains 2 values 'active' and 'inactive'. I can select either of these values for all records and then click on 'submit' button.After clicking submit button Iam calling another jsp which will retrive the values changed in drop down list.My query is how do I get the multiple values changed in drop down in next page and update the database with these values.

Thanks in advance
0
Comment
Question by:kalyanm
  • 3
  • 2
5 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 500 total points
ID: 12555989
Give your drop down boxes different names (based on the id of the row)?

ie:

Row 1
<input type="select" name="1_act">
    <option value="on">activate</option>
    <option value="off">deactivate</option>
</input>
Row 2
<input type="select" name="2_act">
    <option value="on">activate</option>
    <option value="off">deactivate</option>
</input>

then, in your second JSP, you can just go through your items that you displayed to the user, and see if they were set to on or off...

<%
    for( int i = 0 ; i < rows.size() ; i++ )
    {
        String value = request.getParameter( ( i + 1 ) + "_act" ) ;
        if( value != null )
        {
           out.println( "Row " + ( i + 1 ) + " was set to " + value ) ;
           // db stuff here to set this value in the database for row "i"
        }
    }
%>
0
 

Author Comment

by:kalyanm
ID: 12556111
Tim
Thanks for that.But I have a problem Iam printing bewlo the section of code which generates drop down list for all rows and problem is that I cannot give name from option list based of a row as listed below and it generates the same drop down list as many as no of rows as it is in while loop.I wanted to get these into next page and update
<%
      
      ResultSet rslt = null;
        StringBuffer make = new StringBuffer();       
      
        try {                                                                    
                String myDriver="sun.jdbc.odbc.JdbcOdbcDriver";
            String url = "jdbc:odbc:Momqts";
            Class.forName(myDriver);
                Connection conn = DriverManager.getConnection(url);
                Statement stmt = conn.createStatement();
            rslt = stmt.executeQuery("SELECT Emp_no,project_id,Emp_name from members order by " + columnName + " desc");
 
                if(rslt!=null)
            {
                   
                  while(rslt.next())
                  {
                             
                         String mqrid =rslt.getString("Emp_no");
                         String mdate=rslt.getString("project_id");
                         String mid=rslt.getString("Emp_name");
                         make.append(mqrid);
                         make.append("\t");
                   make.append(mdate);
                   make.append("\t");
                     make.append(mid);
                         make.append("\n");
                  
             
%>

<tr>
                       
                  <td width="20%"><%=mqrid%></td>
                  <td width="20%"><%=mdate%></td>
                  <td width="20%"><%=mid%></td>
                        <td width="40%">
                        <select name=emp1>
                        <option value="active" selected>active</option>
                        <option value"inactive">inactive</option>
                        </select>
                        </td>
                  
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12556182
Why not change:

                        <select name=emp1>

to

                        <select name="<%= mqrid + "emp1" %>">
0
 

Author Comment

by:kalyanm
ID: 12556269
Tim
Thanks for advice,i will try with this...
Do I need to set the option to 'on' or 'off' as you have previuosly suggested also Can you please elaborate on the code you have given for 2nd JSP..ie. how do I get rows.size() ?
<%
    for( int i = 0 ; i < rows.size() ; i++ )
    {
        String value = request.getParameter( ( i + 1 ) + "_act" ) ;
        if( value != null )
        {
           out.println( "Row " + ( i + 1 ) + " was set to " + value ) ;
           // db stuff here to set this value in the database for row "i"
        }
    }
%>
and after I get these parameters I have to update the database with the values that have been selected as 'active' only.please advice
0
 

Author Comment

by:kalyanm
ID: 12652798
I hve resolved this and can be closed now
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Applications for our next round of the Experts Exchange Scholarship Contest are starting to roll in. It made us wonder what our past winners are up to these days. Here's a look at what four winners experienced with the contest and what they're doing…
Tech giants such as Amazon and Google have sold Alexa and Echo to such an extent that they have become household names. And soon they are expected to be used by commoners in their homes, ordering takeout, picking out a song, answering trivia questio…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month15 days, 5 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question