Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Passing selected values.

Posted on 2002-06-29
9
139 Views
Last Modified: 2010-04-01
<HTML>
<HEAD>

<TITLE></TITLE>

</HEAD>
<BODY>
<form NAME="ControlPanelForm" method=POST id=form1 name=form1 >
<table >
    <tr>
         <td>
               <select name="ControlPanelOne">
                   <option selected>Choose Option</option>
                   <option value="Reverse.jsp">Reverse</option>
                   <option value="Correct.jsp">Correct</option><option>Download</option><option>Print</option>
              </select>
         </td>
    </tr>
    <tr>
         <td>
              <INPUT type="checkbox" id=checkbox1 name=checkbox1 value="item1">
         </td>
         <td>
              04/14/02
         </td>
        <td >
              <a href="#">421</a>
        </td>
        <td >
              $123,456,789.00
         </td>
        <td >
              $1500.00
         </td>
        <td >
              $1000.00
         </td>
    </tr>
    <tr>
         <td>
              <INPUT type="checkbox" id=checkbox2 name=checkbox2 value="item2">
         </td>
         <td >
              03/09/02
         </td>
         <td >
              <a href="#">422</a>
         </td>
         <td >
              $103,456,789.00
         </td>
         <td >
              $1500.00
         </td>
         <td >
              $0
         </td>
    </tr>
    <tr>
     <td>
         <input type="Submit"  value="Submit"  id=submit1 name=submit1>
    </td>
  </tr>
</table>
</form>

<P>&nbsp;</P>

</BODY>
</HTML>

I have a html form as shown above. When the user selects a check box and chosses a option from the drop down ie either reverse or correct,the user should be presented the reverse.jsp with one row of values which the user selects.If the user selects two checkboxes and chooses reverse from the drop down then he should see two rows of data of the selected ones in Reverse.jsp.
I would like to know as to how to do it. Also in the jsp page i would like to include a javascript that highlights the selected rows.A code for doing this would be appreciated.
Thanks
Ramani
0
Comment
Question by:ramani081399
  • 4
  • 3
  • 2
9 Comments
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 7121321
Try use:

if ((request.getMethod().equals("POST")) {
//change your HTML here
//Use request.getParameter("ControlPanelOne"), as well as request.getParameter("checkbox1") and request.getParameter("checkbox2") to determine what values had been posted.

}
else {

//Show Original HTML here

}
0
 

Author Comment

by:ramani081399
ID: 7123196

ryancys,
Could post a code snippet as to how to do this.

Ramani
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 7123891
Let me check it tonight :) cheers
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Expert Comment

by:naveeth
ID: 7125353
you select reverse from the form it will take to reverse.jsp

===========================================================

<HTML>
<HEAD>

<TITLE></TITLE>
<script>
function jump()
{
var index=document.form1.ControlPanelOne.options.selectedIndex;
var temp=document.form1.ControlPanelOne.options[index].value;
alert(temp);
document.form1.action=temp;
document.form1.submit();
}
</script>

</HEAD>
<BODY>
<form NAME="ControlPanelForm" method=POST id=form1 name=form1 >
<table >
   <tr>
        <td>
              <select name="ControlPanelOne" onchange=jump();>
                  <option selected>Choose Option</option>
                  <option value="Reverse.jsp">Reverse</option>
                  <option value="Correct.jsp">Correct</option><option>Download</option><option>Print</option>
             </select>
        </td>
   </tr>
   <tr>
        <td>
             <INPUT type="checkbox" id=checkbox1 name=checkbox1 value="item1">
        </td>
        <td>
           <INPUT TYPE="hidden" value="04/14/02" name="checkbox1hid1dt1">  04/14/02
        </td>
       <td >
             
                <INPUT TYPE="hidden" value="421" name="checkbox1hid1lk"><a href="#">421</a>
       </td>
       <td >
               <INPUT TYPE="hidden" value="$123,456,789.00" name="checkbox1hid1amt1">
             $123,456,789.00
        </td>
       <td >
               <INPUT TYPE="hidden" value="$1500.00" name="checkbox1hid1amt2">
             $1500.00
        </td>
       <td >
               <INPUT TYPE="hidden" value="$1000.00" name="checkbox1hid1amt3">
             $1000.00
        </td>
   </tr>
   <tr>
        <td>
             <INPUT type="checkbox" id=checkbox2 name=checkbox2 value="item2">
        </td>
        <td>
           <INPUT TYPE="hidden" value="05/14/02" name="checkbox1hid2dt1">  04/14/02
        </td>
       <td >
             
                <INPUT TYPE="hidden" value="422" name="checkbox1hid2lk"><a href="#">421</a>
       </td>
       <td >
               <INPUT TYPE="hidden" value="$1256,456,789.00" name="checkbox1hid2amt1">
             $123,456,789.00
        </td>
       <td >
               <INPUT TYPE="hidden" value="$15560.00" name="checkbox1hid2amt2">
             $1500.00
        </td>
       <td >
               <INPUT TYPE="hidden" value="$78.00" name="checkbox1hid2amt3">
             $1000.00
        </td>
   </tr>
   <tr>
    <td>
        <input type="Submit"  value="Submit"  id=submit1 name=submit1>
   </td>
 </tr>
</table>
</form>

<P>&nbsp;</P>

</BODY>
</HTML>

===========================================================
0
 
LVL 1

Expert Comment

by:naveeth
ID: 7125362
this is your
Reverse.jsp
================================================


<%!
String strcheck1="";
String strcheck2="";
String strdt="";
String stramt1="";
String stramt2="";
String stramt3="";
String strlnk="";

%>
<%
strcheck1 = request.getParameter("checkbox1");
System.out.println("strcheck1"+strcheck1);
if (strcheck1 != null)
{
if(strcheck1.equals("item1"))
{
     strdt = request.getParameter("checkbox1hid1dt1");
     stramt1 = request.getParameter("checkbox1hid1amt1");
     stramt2 = request.getParameter("checkbox1hid1amt2");
     stramt3 = request.getParameter("checkbox1hid1amt3");
     strlnk = request.getParameter("checkbox1hid1lk");
%>

     <TABLE>
<TR>
     <TD><%=strdt%></TD>
     <TD><A HREF="#"><%=strlnk%></A></TD>
     <TD><%=stramt1%></TD>
     <TD><%=stramt1%></TD>
     <TD><%=stramt1%></TD>
</TR>
<%}}
strcheck2 =(String) request.getParameter("checkbox2");
System.out.println("strcheck1"+strcheck2);
if (strcheck2 != null)
{
if(strcheck2.equals("item2"))
{
     System.out.println("inside if");
     strdt = request.getParameter("checkbox1hid2dt1");
     stramt1 = request.getParameter("checkbox1hid2amt1");
     stramt2 = request.getParameter("checkbox1hid2amt2");
     stramt3 = request.getParameter("checkbox1hid2amt3");
     strlnk = request.getParameter("checkbox1hid2lk");
%>

<TR>
     <TD><%=strdt%></TD>
     <TD><A HREF="#"><%=strlnk%></A></TD>
     <TD><%=stramt1%></TD>
     <TD><%=stramt1%></TD>
     <TD><%=stramt1%></TD>
</TR>
<%}
}
%>
</TABLE>
0
 
LVL 1

Expert Comment

by:naveeth
ID: 7125370
keep both the files in same directory and select reverse from ur drop down it will take u to to Reverse.jsp.it will display 1 row if u select 1 and 2 if selecte 2.
regards
0
 
LVL 50

Accepted Solution

by:
Ryan Chong earned 100 total points
ID: 7126077
naveeth, please allow me to post some of my comments here despite it seems to be some partial duplicated. Bcos i don't want to waste my effort ! :)

Here is the post:

Hi ramani,

This is your original HTML you posted above, here me do some minor changes on it to make it dynamically change the page Action after the item is selected from Drop down Menu.
---test.jsp---

<HTML>
<HEAD>

<TITLE></TITLE>

</HEAD>
<BODY>
<form NAME="ControlPanelForm" method=POST id=form1>
<table >
   <tr>
        <td>
              <select name="ControlPanelOne" onclick="javascript:document.ControlPanelForm.action=document.ControlPanelForm.ControlPanelOne.value;">
                  <option selected>Choose Option</option>
                  <option value="Reverse.jsp">Reverse</option>
                  <option value="Correct.jsp">Correct</option>
                          <option>Download</option>
                          <option>Print</option>
             </select>
        </td>
   </tr>
   <tr>
        <td>
             <INPUT type="checkbox" name=checkbox1 value="item1">
        </td>
        <td>
             04/14/02
        </td>
       <td >
             <a href="#">421</a>
       </td>
       <td >
             $123,456,789.00
        </td>
       <td >
             $1500.00
        </td>
       <td >
             $1000.00
        </td>
   </tr>
   <tr>
        <td>
             
        <INPUT type="checkbox" name=checkbox2 value="item2">
        </td>
        <td >
             03/09/02
        </td>
        <td >
             <a href="#">422</a>
        </td>
        <td >
             $103,456,789.00
        </td>
        <td >
             $1500.00
        </td>
        <td >
             $0
        </td>
   </tr>
   <tr>
    <td>
        <input type="submit"  value="Submit"  id=submit1 name=submit1>
   </td>
 </tr>
</table>
</form>
<P>&nbsp;</P>

</BODY>
</HTML>

---test.jsp---

And i have created a Reverse.jsp which will contain the selected items' value:

---Reverse.jsp---

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<script languange = "javascript">
      function preselected() {
            var selecteditem = "<%=request.getParameter("ControlPanelOne")%>";
            var j = document.ControlPanelForm.ControlPanelOne.length;
            
            for (i=0; i<=j; i++) {
                  if (selecteditem == document.ControlPanelForm.ControlPanelOne.options[i].value) {
                        document.ControlPanelForm.ControlPanelOne.selectedIndex = i;
                        break;
                  }                  
            }            
      }
</script>


<body bgcolor="#FFFFFF" text="#000000" Onload="javascript:preselected();">
<form NAME="ControlPanelForm" method=POST id=form1>
<p>Reverse.jsp </p>
<table >
  <tr>
    <td>
      <select name="ControlPanelOne" onClick="javascript:document.ControlPanelForm.Action=document.ControlPanelForm.ControlPanelOne.value;">
        <option selected>Choose Option</option>
        <option value="Reverse.jsp">Reverse</option>
        <option value="Correct.jsp">Correct</option>
        <option>Download</option>
        <option>Print</option>
      </select>
    </td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" name=checkbox1 value="item1" <%=(request.getParameter("checkbox1")==null)?"":"Checked" %>>
    </td>
    <td> 04/14/02 </td>
    <td > <a href="#">421</a> </td>
    <td > $123,456,789.00 </td>
    <td > $1500.00 </td>
    <td > $1000.00 </td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" name=checkbox2 value="item2" <%=(request.getParameter("checkbox2")==null)?"":"Checked" %>>
    </td>
    <td > 03/09/02 </td>
    <td > <a href="#">422</a> </td>
    <td > $103,456,789.00 </td>
    <td > $1500.00 </td>
    <td > $0 </td>
  </tr>
  <tr>
    <td>
      <input type="submit"  value="Submit"  id=submit1 name=submit1>
    </td>
  </tr>
</table>
<p>&nbsp;</p>
</form>
</body>
</html>

---Reverse.jsp---

As you can see it's similar to test.jsp. But instead just include some extra jsp/javascript codes. The Reverse.jsp includes a javascript that pre-select an item in Menu > as you requested.

But the examples above is not good enough as we not grouping the checkboxes with same name, so we should name them as the same name, example: name all checkboxes as "checkbox1". Then we need to change the code from request.getParameter("checkbox1") to request.getParameterValues("checkbox1").

regards
ryancys
0
 

Author Comment

by:ramani081399
ID: 7126711
Ryancys

   Thanks.
Ramani
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 7131223
Thanks for grade 'A'.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
method inner class 6 83
oracle fusion vs MQ 2 122
struts spring hibernate example 12 131
how to debug htl and js pages 8 39
If you are looking at this article, you have most likely been hit by some version of ransomware and are trying to find out if there is anything you can do, or what way you should react - READ ON!
This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question