Im making a dependent drop down for my application for filtering purpose. I have populated the drop down from the database and retrieved in the html.
[HTML]
<tr>
<td valign="top" width="138" height="26"><small><font face="Verdana"><strong>Branch</strong></font></small></td>
<td width="379" height="26">
<select name="branch" size="1" onChange="messValue()">
<option value="">(select branch)</option>
<%
publicity.Pub1Form pfObj = null;
ArrayList list =(ArrayList)request.getAttribute("list");
for(Iterator itr = list.iterator(); itr.hasNext();){
pfObj=(Pub1Form)itr.next();{
%>
<option value="<%=pfObj.getDescription() %>"><%=pfObj.getDescription() %></option>
<%}} %>
<option value="">-------------------------------------------------------</option>
</select>
<%session.setAttribute("list",list); %>
</td>
</tr>
[/HTML]
This is the arraylist from where i populate the select. My generated page looks like this..
[HTML]
<select name="branch" size="1" onChange="messValue()">
<option value="">(select branch)</option>
<option value="Bombay">Bombay</option>
<option value="Delhi">Delhi</option>
<option value="Ahmedabad">Ahmedabad</option>
and so on....
[/HTML]
this is in my a.jsp(for example).
The javascript ive written is..
Expand|Select|Wrap|Line Numbers
- <script type="text/javascript">
- function messValue(){
- var messageIndex = document.arch.branch.selectedIndex;
- var selectedValue = document.arch.branch.options[messageIndex].value;
- document.arch.branch.value = selectedValue;
- document.arch.submit();
- }
- </script>
regards,
ajos