wood burning stoves*
The moose likes JSP and the fly likes Problem in Selecting values from select  tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem in Selecting values from select  tag" Watch "Problem in Selecting values from select  tag" New topic
Author

Problem in Selecting values from select tag

Ahmed Shaikh
Ranch Hand

Joined: Jul 25, 2005
Posts: 51
Hi plz help me in solving this issue..
In my .jsp there is two select tags in which after selecting a value from one select tag then the related values should be display in another select List.

ex:-is first select contain ABC,BCD,EFG.
then on selecting ABC in first selection List the Secong List will show A,B,C.
This selection shpuld be dynamic.

plzzzzzzzzz help me as soon as possible.
Thanx in advance.....
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41186
    
  45
Why don't you show us what you have so far, that would make it easier to help you with the missing pieces.


Ping & DNS - my free Android networking tools app
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
You have two options:
1. use Javascript
2. after you select item, submit it back to server and create new response to view vith new list populated


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Ahmed Shaikh
Ranch Hand

Joined: Jul 25, 2005
Posts: 51
Hi David Ulicny
Thanx a lot for your help ,is it possible for you to provide me a sample code for it..if yes then i will be thax full to you..
Ahmed Shaikh
Ranch Hand

Joined: Jul 25, 2005
Posts: 51
Hi i have some problem in this given code.
Problem is that when i am trying to retrive value of second select tag in my servlet it is giving "null" value.

String resource_name = request.getParameter("resource");
it is showing resource_name as a "null".
plz help me in solving this problem......


<form method="post" action="SubmitJob.jsp" name="serviceForm" id="serviceForm">

<table width="100%" border="0" cellspacing="5" cellpadding="1" style="margin-top: 5em" class="style1">

<tr>

<td align="right" ><A Href="Status1.jsp">Check Status</A></td>
</tr>

<tr>
<td><b>
<%=jmsProp.getProperty("label.SelectService")%>:<b>
<select name="services" onChange="serviceForm.submit();">
<option SELECTED><%=jmsProp.getProperty("label.SelectService")%></option>
<%
serviceData=new com.quest.JMS.db.JMSDataBaseService();
List services=serviceData.getServices();
Iterator iter=services.iterator();
while(iter.hasNext()){
String serviceName=(String)iter.next();
%>
<option value="<%=serviceName%>"> <%=serviceName%> </option>
<%
}
%>

</select>
</td>
</tr>

<tr>
<td>
<b><%=jmsProp.getProperty("label.SelectResource")%></b>

<select name="resource">
<option SELECTED><%=jmsProp.getProperty("label.SelectResource")%></option>
<%
serviceData=new com.quest.JMS.db.JMSDataBaseService();
String selectedService= (String)request.getParameter("services");
if(request.getParameter("services")!=null){
if(!request.getParameter("services").equals("Select Service")){

List resources=serviceData.getResources(selectedService);

Iterator resourceiter=resources.iterator();
while(resourceiter.hasNext()){
String resourceName=(String)resourceiter.next();
%>
<option value="<%=resourceName%>"> <%=resourceName%> </option>
<%

}
}
}
%>
</select>
</td>
</tr>
</form>
<form method="post" action="JobSubmitServlet" name="upform" enctype="multipart/form-data">
<tr>
<td><b>
<%=jmsProp.getProperty("label.CommandLine")%> :</b>
<input type="text" name="commandline" size="20">
</td>
</tr>
<tr>
<td align="left"><b><%=jmsProp.getProperty("label.selectFile")%> :</b>
</td>
</tr>
<tr>
<td align="left">
<input type="file" name="uploadfile" size="50">
</td>
</tr>
<tr>
<td align="left">
<input type="hidden" name="todo" value="upload">
<input type="submit" name="Submit" value="Upload">
<input type="reset" name="Reset" value="Cancel">
</td>
</tr>
</table>
</td>
</tr>
</table>

</form>
Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
Please explain the steps that you are performing when you get the NULL value for second select. I am not sure if you have the second select box loaded when you are trying to retrieve from request.
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
At first, think about refactoring this code.
Mohen Vijay is right, it's not clear if resource is loaded.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Ahmed,

Javaranch Tip:
If you're going to post more than a line or two of your code, wrap it in UBB Code tags (there is a button on the edit screen to assist with this). They preserve your indening which makes the code easier to read. This usually results in more people reading it an helping you.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ahmed Shaikh
Ranch Hand

Joined: Jul 25, 2005
Posts: 51
Hi All,
Thank a lot for your advise.
Ahmed Shaikh
Ranch Hand

Joined: Jul 25, 2005
Posts: 51
Hi All,
Thank a lot for your advise.
I am new to forum so i dont know how to post a Query,Now i am ok with all this ,again thanx a lot.

will you solve my one more problem.
Problem :--
while clicking a link on a page, content of that link will be display on same page at right side.

plz provide me a code for this ........

Thanx in advance
Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
Couple of quick questions.

Are you using FRAMES ??

Do you submit your form for the page to refresh with the details ?

If you are submitting the form, it should be straightforward to get the page loaded with the new information.
Ahmed Shaikh
Ranch Hand

Joined: Jul 25, 2005
Posts: 51
Hi Mohen,
Thanx for reply.
1. I am not using Frames,even i dont know how to use Frames in jsp. is it possible?

2.yes i am doing so,but even it is taking null values.

Now i am using <jsp:include> to include a page.

is there any other method to do it? if yes then plz help me with example.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you want an example, there is one on my site:
http://simple.souther.us/not-so-simple.html
Look for DynamicSelectLists.

It's not straight JSP though.
The whole app is written in MVC.
Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
You can also ask on the Javascript/HTML forum about this. A common way to have dynamic lists is using AJAX - once you select an item from the first list, javascript uses the XMLHttpRequest object to contact the server for data for the second list, and populates the second list with it. The main page doesn't need to reload, the request happens behind the scenes.

A hidden iframe is a way to do the same thing, only it's a bit hackish and ugly. Once the first list is changed, a hidden iframe is submitted. Once it returns with the data, it's onload function can be used to populate the second list.

-Yuriy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in Selecting values from select tag
 
Similar Threads
Dynamic Changes in JSP - Urgent
Multi Column List
YUI Autocomplete with XML and JSP
Reg : Drop-down box
Dynamic addition of items to combo inJSP