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

saleemkhanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Murali MurugesanFull stack Java developerCommented:

<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*




 
0
saleemkhanAuthor Commented:
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);
 
0
Murali MurugesanFull stack Java developerCommented:
fine if you want it to do it without servlets its fine.

try the attached..

-Murali*
<body>
<form name="f1" action="/same jsp name">
<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"/>
 
<%if(request.getParameter("h1").value != null){
  orders=new orderInfo();  //orderInfo is my Java class
  pOrders=new Vector();
  pOrders=orders.getPendingOrders(id);
}%>
 
 
<%if(pOrders != null){
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>
<% }
}
  }
%>
</form>
 
</body>
 
 
<script>
function submitfrm(sortValue){
     document.f1.h1.value=sortValue;
     document.f1.submit();
}
</script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Murali MurugesanFull stack Java developerCommented:
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();
}
0
saleemkhanAuthor Commented:
Excellent solution.

Thanks a million
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.