Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in Selecting values from select tag

 
Ahmed Shaikh
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you show us what you have so far, that would make it easier to help you with the missing pieces.
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ahmed Shaikh
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At first, think about refactoring this code.
Mohen Vijay is right, it's not clear if resource is loaded.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ahmed Shaikh
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Thank a lot for your advise.
 
Ahmed Shaikh
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic