469,271 Members | 1,776 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Help needed in retrieving the selected values in the next page.:)

283 100+
Hello friends,
After thinking about this for sometime, i decided to post this in the java forum.
Well my problem here in detail is, i have 3 jsp pages where in a.jsp(for example) i have a combo box, based on the selection of the value in that combo box, b.jsp page gets populated with the value associated to a.jsp, and again based on the selection of value of the 2nd combobox my 3rd combo box gets populated, which is in c.jsp. I'm able to retrieve the values of all the 3 combo box, but im stuck at a point.
This is what i have done.....
a.jsp
[HTML]
<select name="branch" size="1" onChange="messageValue()">
<option value="">(Select Branch)<option>
<option value="Bombay" <%= branch.equals("Bombay") ? "selected" : "" %>>Bombay</option>
<option value="Delhi" <%= branch.equals("Delhi") ? "selected" : "" %>>Delhi</option>
and so on...
</select>
[/HTML]
the corresponding javascript is...
Expand|Select|Wrap|Line Numbers
  1.     function messageValue(){
  2. var messageIndex = document.expenqryForm.branch.selectedIndex;
  3. var selectedValue = document.expenqryForm.branch.options[messageIndex].value;
  4. document.expenqryForm.branch.value = selectedValue;
  5. document.expenqryForm.submit();
  6. }
  7.  
b.jsp page
[HTML]
<select name="branch" size="1" onChange="messageValue()">
<option value=""><option>
<option value="Bombay" <%= branch.equals("Bombay") ? "selected" : "" %>>Bombay</option>
<option value="Delhi" <%= branch.equals("Delhi") ? "selected" : "" %>>Delhi</option>
[/HTML]

and

Expand|Select|Wrap|Line Numbers
  1. <option value="">(select all)</option>
  2.      <%String publiCode=(String)request.getParameter("publiCode");
  3.     String publiHead=(String)request.getParameter("publiHead");
  4.     %>
  5.     <%publicity.ExpenForm eqobj=null;
  6.       ArrayList list=(ArrayList)request.getAttribute("pubHead");
  7.       for(Iterator itr=list.iterator();itr.hasNext();){
  8.       eqobj=(ExpenForm)itr.next();{    
  9.           %>
  10.  
  11.         <option value="<%=eqobj.getPubliCode() %>"><%=eqobj.getPubliHead() %></option>
  12.         <%}} %>
  13.     </select>
  14. <%session.setAttribute("list",list); %>
  15.  
the associated js function....
Expand|Select|Wrap|Line Numbers
  1. function messValue()
  2.     {
  3.       var messIndex = document.expen2Form.publiCode.selectedIndex;
  4.       var selValue = document.expen2Form.publiCode.options[messIndex].value;
  5.       document.expen2Form.publiCode.value=selValue;
  6.       document.expen2Form.publiHead.value=selValue;
  7.       document.expen2Form.submit();
  8.     }
  9.  

c.jsp page...
[HTML]//here i want to show the selected value of the previous page along with //other values
<option value="">(select all)</option>
<%
String publiCode = request.getParameter("publiCode");
publicity.ExpenForm eqobj1=null;
java.util.ArrayList list=(java.util.ArrayList)session.getAttribute("li st");
for(Iterator it=list.iterator();it.hasNext();){
eqobj1=(ExpenForm)it.next();{ %>
<option selected value="<%=eqobj1.getPubliCode() %>" <%=publicity_Code.equals(publiCode) ? "selected" : "" %> ><%=eqobj1.getPubliHead() %></option>
<%}} %>
</select>

[/HTML]


What i want to achieve here is, i want to send(show) the values which i select from the b.jsp page(which is comming from arraylist) to the next i.e c.jsp page with the selected value first and then the rest of the values.
At this point how im doing it is setting the arraylist in session and then populating it in the next page.....but in the c.jsp im getting the last value as selected even though i select some other value(i know why:))....i'm not sure this may be more of a js question....but since it involves jsp im putting it here.
Please help me coz im stuck here for some time now.:)..I hope ive conveyed myself clearly.:)

regards,
ajos
Feb 2 '08 #1
9 9475
r035198x
13,262 8TB
The selected value is easy to get.
Expand|Select|Wrap|Line Numbers
  1. request.getParameter("selectName");
To get all the values that were in the select, you can include a hidden combobox (multiple) that you populate with all the values. On submit of the form, call a javascript function which selects all the values in that hidden select an submit it. You then get all its values in the next page using
Expand|Select|Wrap|Line Numbers
  1. request.getParameterValues("hiddenComboboxName");
Feb 2 '08 #2
ajos
283 100+
The selected value is easy to get.
Expand|Select|Wrap|Line Numbers
  1. request.getParameter("selectName");
To get all the values that were in the select, you can include a hidden combobox (multiple) that you populate with all the values. On submit of the form, call a javascript function which selects all the values in that hidden select an submit it. You then get all its values in the next page using
Expand|Select|Wrap|Line Numbers
  1. request.getParameterValues("hiddenComboboxName");
Hi r0 thanks for the reply,
In my a.jsp the option values are hard coded, hence i just used js to get the value in the next page. But in my b.jsp page the value is getting populated by an arraylist.
Expand|Select|Wrap|Line Numbers
  1. <select name="publicity_Code" size="1" onChange="messageValue()">
  2.  
  3.     <option value="">(select all)</option>
  4.      <%String publiCode=(String)request.getParameter("publiCode");
  5.     String publiHead=(String)request.getParameter("publiHead");
  6.     %>
  7.  
  8.     <%publicity.ExpenForm eqobj=null;
  9.       ArrayList list=(ArrayList)request.getAttribute("pubHead");
  10.       for(Iterator itr=list.iterator();itr.hasNext();){
  11.       eqobj=(ExpenForm)itr.next();{    
  12.           %>
  13.  
  14.         <option value="<%=eqobj.getPubliCode() %>"><%=eqobj.getPubliHead() %></option>
  15.         <%}} %>
  16.  
  17.     </select>
  18.  
As you can see the value of the options im getting is different and the value to be displayed is different. Im confused on how to populate the values in the c.jsp page in a drop down showing the selected value.

Edit:did i mention combo box in my post....Im sorry its dropdown:)
Feb 2 '08 #3
r035198x
13,262 8TB
Hi r0 thanks for the reply,
In my a.jsp the option values are hard coded, hence i just used js to get the value in the next page. But in my b.jsp page the value is getting populated by an arraylist.
Expand|Select|Wrap|Line Numbers
  1. <select name="publicity_Code" size="1" onChange="messageValue()">
  2.  
  3.     <option value="">(select all)</option>
  4.      <%String publiCode=(String)request.getParameter("publiCode");
  5.     String publiHead=(String)request.getParameter("publiHead");
  6.     %>
  7.  
  8.     <%publicity.ExpenForm eqobj=null;
  9.       ArrayList list=(ArrayList)request.getAttribute("pubHead");
  10.       for(Iterator itr=list.iterator();itr.hasNext();){
  11.       eqobj=(ExpenForm)itr.next();{    
  12.           %>
  13.  
  14.         <option value="<%=eqobj.getPubliCode() %>"><%=eqobj.getPubliHead() %></option>
  15.         <%}} %>
  16.  
  17.     </select>
  18.  
As you can see the value of the options im getting is different and the value to be displayed is different. Im confused on how to populate the values in the c.jsp page in a drop down showing the selected value.

Edit:did i mention combo box in my post....Im sorry its dropdown:)
It doesn't matter if the values are coming from an arraylist. You can still add them to a hidden dropdown using JSP code.
Feb 2 '08 #4
ajos
283 100+
It doesn't matter if the values are coming from an arraylist. You can still add them to a hidden dropdown using JSP code.
Ok i did something like this...
in b.jsp page
[HTML]
<input type=hidden name="publiCode" value=<%=eqobj.getPubliCode() %>>
<input type=hidden name="publiHead" value=<%=eqobj.getPubliHead() %>>
<input type=hidden name="publicity_Code" value=<%=publicity_Code %>>
[/HTML]

and in c.jsp page
[HTML]
<select name="publicity_Code" size="1">

<option value="">(select all)</option>

<option value="<%=pubCode %>"><%=pubHead %></option>

</select>
[/HTML]
But only the last value from the list is getting populated in the c.jsp page
Feb 2 '08 #5
ajos
283 100+
At present the way i'm retrieving the values in c.jsp is by setting the arraylist from b.jsp in session and then retrieving the value in c.jsp....but when i select a particular value from b.jsp,....in c.jsp page the last value is shown as selected event though internally the result is showing correctly for the original selected value...Please help me in this situation.
Feb 2 '08 #6
r035198x
13,262 8TB
I thought you said you have the values in an arraylist.
So basically you'd have
Expand|Select|Wrap|Line Numbers
  1. ArrayList<String> list = getValues();
  2. <select name ="data" style="display:none" multiple>
  3. <%
  4.           for(String value : list) {
  5. %>
  6.      <option value ="<%=value%>"> <%=value%> 
  7. <%
  8.          }
  9. %>
This select would be on the form that you want to submit to c.jsp but would not be displayed to the user.
On submit of this form call a Javascript function called, say, selectAll which selects all the values in the select above.

In c.jsp you can get all the values of this select using
Expand|Select|Wrap|Line Numbers
  1. request.getParameterValues("data");
Disclaimer: Been a while since I wrote any web related code so you might have to check it a bit.
Feb 2 '08 #7
ajos
283 100+
I thought you said you have the values in an arraylist.
So basically you'd have
Expand|Select|Wrap|Line Numbers
  1. ArrayList<String> list = getValues();
  2. <select name ="data" style="display:none" multiple>
  3. <%
  4.           for(String value : list) {
  5. %>
  6.      <option value ="<%=value%>"> <%=value%> 
  7. <%
  8.          }
  9. %>
This select would be on the form that you want to submit to c.jsp but would not be displayed to the user.
On submit of this form call a Javascript function called, say, selectAll which selects all the values in the select above.

In c.jsp you can get all the values of this select using
Expand|Select|Wrap|Line Numbers
  1. request.getParameterValues("data");
Disclaimer: Been a while since I wrote any web related code so you might have to check it a bit.
Ok now i know this should be easy......im doing the same thing here, but slightly different from your code snippet...
Expand|Select|Wrap|Line Numbers
  1. <select name="publicity_Code" size="1" onChange="messageValue()">
  2.     <option value="">(select all)</option>
  3.     <%publicity.ExpenForm eqobj=null;
  4.       ArrayList list=(ArrayList)request.getAttribute("pubHead");
  5.       for(Iterator itr=list.iterator();itr.hasNext();){
  6.       eqobj=(ExpenForm)itr.next();{    
  7.           %>
  8.     <option value="<%=eqobj.getPubliCode() %>"><%=eqobj.getPubliHead() %></option>
  9.         <%}} %>
  10.     </select>
  11.  
If you notice here, in the <option> i have value attribute <%=eqobj.getPubliCode() %> and also the value to display as <%=eqobj.getPubliHead() %> from the bean. My question here is how do i store the values of the publiCode and publiHead values in js and populate in c.jsp completely with the value as selected. Im getting confused here ive done this before in a.jsp to b.jsp but the values were hard coded and in b.jsp i checked the condition as--
Expand|Select|Wrap|Line Numbers
  1. <option value="Bombay" <%= branch.equals("Bombay") ? "selected" : "" %>>Bombay</option>
.
Im not sure on how to do it in this case.
Feb 2 '08 #8
ajos
283 100+
Do i need to do set the ArrayList values in the b.jsp page and retrieve it in the c.jsp page, or can it be done by some other way?
Feb 2 '08 #9
ajos
283 100+
Do i need to do set the ArrayList values in the b.jsp page and retrieve it in the c.jsp page, or can it be done by some other way?
How do i retrieve the values of the dropdown from b.jsp page to c.jsp page without sending the arraylist to c.jsp page?...i guess this is the last part of my mission, so to speak:). Ive been able to write the javascript assciated with it...can somebody help me in retrieving the value in c.jsp page?
Feb 2 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by krzysiek | last post: by
2 posts views Thread by walrama | last post: by
reply views Thread by sconnoll | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.