Link to home
Start Free TrialLog in
Avatar of saleemkhan
saleemkhan

asked on

How to Populate Data from Db on change event of Drop down list?

Hi all,
      i would like to Display data retrieved from DB  in a Jsp onchange event of drop down list.
     
      Waiting for an expert solution.
This is the existing code.
 
<SELECT name="SortStatus">
	<option value="1" selected>ALL</option>
	<option value="2" >Date</option>
	<option value="3">Priority</option>
	<option value="4">Status</option>
</SELECT>
 
 
<%
orders=new orderInfo();
pOrders=new Vector();
pOrders=orders.getPendingOrders(id);
 
 
<%for (Iterator iter = pOrders.iterator(); iter.hasNext();)
          {
	        orders= iter.next();
    	     if (orders !=null)
        	    {
            	                             
             %>
         
  <tr>
     		                     
 <td width='5%'   align='center' bgcolor="#CCCC99"><font face='Arial' size="1"><%=(orders.getOrd_no()== null? "":orders.getOrd_no())%>			     <td width='5%'   align='center' bgcolor="#CCCC99"><font face='Arial' size="1"><%=(orders.getOrd_dt()== null? "":orders.getOrd_dt())%>
<td width='5%'   align='center' bgcolor="#CCCC99"><font face='Arial' size="1"><%=(orders.getOrd_rec_dt()== null? "":orders.getOrd_rec_dt())%></font></td>
<td width='5%'   align='center' bgcolor="#CCCC99"><font face='Arial' size="1"><%=(orders.getCustName()== null? "":orders.getCustName())%></font></td>
 </table>
<% }
  }
%>
 
 
my query is   <select name="SortStatus" onchange event i should create  like below 
 
pOrders=orders.getPendingOrders(id,SortStatus);
 
Any idea will be highly appreciated.

Open in new window

Avatar of Murali Murugesan
Murali Murugesan
Flag of Australia image


<form name="f1" action="<to some servlet>">
<SELECT name="SortStatus" onchange="submitfrm(this.value)">
        <option value="1" selected>ALL</option>
        <option value="2" >Date</option>
        <option value="3">Priority</option>
        <option value="4">Status</option>
</SELECT>
<input type="hidden" value="" name="h1"/>
</form>

<script>
function submitfrm(sortValue){
     document.f1.h1.value=sortValue;
     document.f1.submit();
}
</script>


In your servlet or action class incase of struts,

1. get the value of h1 getParameter("h1").
2. request.setAttribute("pendingOrders",orders.getPendingOrders(id,SortStatus));
3. redirect the page.

-Murali*




 
Avatar of saleemkhan
saleemkhan

ASKER

hi ,
   I am displaying the data in the same page.I dont have a servlet or action class its  a java class(orderInfo)  i.e
<SELECT name="SortStatus">
      <option value="1" selected>ALL</option>
      <option value="2" >Date</option>
      <option value="3">Priority</option>
      <option value="4">Status</option>
</SELECT>
 
 
<%
orders=new orderInfo();  //orderInfo is my Java class
pOrders=new Vector();
pOrders=orders.getPendingOrders(id); //Inside orderinfo class i have a method getPendingOrders which return a vector
 
 <!-- i am iterating the vector and dispalying the data like below -->

<%for (Iterator iter = pOrders.iterator(); iter.hasNext();)
          {
              orders= iter.next();
               if (orders !=null)
                  {
                                              
             %>
         
  <tr>
                                     
 <td width='5%'   align='center' bgcolor="#CCCC99"><font face='Arial' size="1"><%=(orders.getOrd_no()== null? "":orders.getOrd_no())%>                       <td width='5%'   align='center' bgcolor="#CCCC99"><font face='Arial' size="1"><%=(orders.getOrd_dt()== null? "":orders.getOrd_dt())%>
<td width='5%'   align='center' bgcolor="#CCCC99"><font face='Arial' size="1"><%=(orders.getOrd_rec_dt()== null? "":orders.getOrd_rec_dt())%></font></td>
<td width='5%'   align='center' bgcolor="#CCCC99"><font face='Arial' size="1"><%=(orders.getCustName()== null? "":orders.getCustName())%></font></td>
 </table>
<% }
  }
%>
 
 
my query is   <select name="SortStatus" onchange event i should create  like below
 
pOrders=orders.getPendingOrders(id,SortStatus);
 
ASKER CERTIFIED SOLUTION
Avatar of Murali Murugesan
Murali Murugesan
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
to add to the above if u have multiple actions to submit then you add the action in the js function as below,

function submitfrm(sortValue){
      document.f1.h1.value=sortValue;
     document.f1.action ="/same jsp page";
     document.f1.submit();
}
Excellent solution.

Thanks a million