Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

when i select multiple check box's for multiple empId's  and enter submit how to capture the empNO's to the corresponding empId;

Posted on 2006-11-03
17
Medium Priority
?
2,039 Views
Last Modified: 2012-05-05

execute the below sample jsp;

this is a sample jsp ;when i select multiple check box's for multiple empId's  and enter submit how to capture the empNO's to the corresponding empId;

<%for(int i=0;i<10;i++)
{%>
<tr class='formheader' align=center>
<td>
<input type="checkbox" id="empId<%=i%>" name="empId" value="<%=i%>"><%=i%>
<input type="hidden" id="empNO<%=i%>" name="empNO" value="AAA<%=i%>">
</td>
</tr>
<%}%>

</table>
<input type="button" value="Submit" onclick="ex()">

</form>

 but i want only checked values here
<%
out.println(request.getParameterValues("empId"));
out.println(request.getParameterValues("empNO"));

%>
0
Comment
Question by:chaitu chaitu
[X]
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
  • 7
  • 7
  • 2
17 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 1200 total points
ID: 17866886
<%
    for(int i=0;i<10;i++)
    {
%>
  <tr class='formheader' align=center>
    <td>
      <input type="checkbox" name="empId" value="<%=i%>"><%=i%>
      <input type="hidden" name="<%= "empNO" + i %>" value="AAA<%=i%>">
    </td>
  </tr>
<%
    }
%>

</table>
<input type="button" value="Submit" onclick="ex()">

</form>

<%
    String[] ids = request.getParameterValues( "empId" ) ;
    for( String id : ids )
    {
        out.println( id + " : " + request.getParameter( "empNO" + id ) ) ;
    }
%>
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 17872123
may i know what is meaning of this

for( String id : ids )
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 17872188
below code not fetching me checked values;

<script>

function ex()
{
                        Url      =      'check.jsp';
                        document.forms[0].action = Url;
                        document.forms[0].submit();
}
</script>

<form action="second_page.jsp" method="post">

<%
    for(int i=0;i<10;i++)
    {
%>
  <tr class='formheader' align=center>
    <td>
      <input type="checkbox" name="empId" value="<%=i%>"><%=i%>
      <input type="hidden" name="empNO<%=i%>" value="AAA<%=i%>">
    </td>
  </tr>
<%
    }
%>

</table>
<input type="button" value="Submit" onclick="ex()">

</form>

<%
    String[] ids = request.getParameterValues( "empId" ) ;
      if(ids != null && ids.length > 0)
      {
    for(int id=0;id<ids.length;id++ )
    {
        out.println( id + " : " + request.getParameter( "empNO" + id ) ) ;
    }
      }
%>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 35

Expert Comment

by:TimYates
ID: 17872875
>> for( String id : ids )

loops through the ids array, putting each value into id in turn

You need Java 1.5+
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 17873733
>>>
for(int id=0;id<ids.length;id++ )
    {
        out.println( id + " : " + request.getParameter( "empNO" + ids[id] ) ) ;
    }
     }
%>

should work.
I thought I answered the same question a couple of days ago for you...!!!
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 17875372
thats for radio button here checkboxes;;
0
 
LVL 35

Expert Comment

by:TimYates
ID: 17875861
So I get the small share of the points do I chaituu

Thanks...

!
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 17875887
its actually

out.println( id + " : " + request.getParameter( "empNO" + ids[id] ) ) ;

not

out.println( id + " : " + request.getParameter( "empNO" + id ) ) ;
0
 
LVL 35

Expert Comment

by:TimYates
ID: 17875924
it depends if you use the Java 5 for loop like I had, or the old style for loop like you had

Yes, putting my code into your loop didn't work

But that's hardly suprising
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 17875952
this sentence is important naa to display o/p ;

request.getParameter( "empNO" + ids[id] )
0
 
LVL 35

Expert Comment

by:TimYates
ID: 17875956
<%
    String[] ids = request.getParameterValues( "empId" ) ;
    for( String id : ids )
    {
        out.println( id + " : " + request.getParameter( "empNO" + id ) ) ;
    }
%>

Will work with Java 5

...as I said before
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 17875995
rightnow i am working in java 1.5 only;;

for( String id : ids )  

equals to

for(int id=0;id<ids.length;i++) in old style;


i think  request.getParameter( "empNO" + id )  it is wrong;;


0
 
LVL 35

Expert Comment

by:TimYates
ID: 17875998
   for( String id : ids )
        out.println( request.getParameter( "empNO" + id ) ) ;

in 1.5 is EXACTLY the same as:

    for( int id = 0 ; id < ids.length ; id++ )
        out.println( request.getParameter( "empNO" + ids[ id ] ) ) ;

in 1.4
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 17876001
ok i will ask the moderator to reopen the question
0
 
LVL 19

Assisted Solution

by:Kuldeepchaturvedi
Kuldeepchaturvedi earned 800 total points
ID: 17876723
As Mr. Tim is saying....

  for( String id : ids )
        out.println( request.getParameter( "empNO" + id ) ) ;

in 1.5 is EXACTLY the same as:

    for( int id = 0 ; id < ids.length ; id++ )
        out.println( request.getParameter( "empNO" + ids[ id ] ) ) ;


so if you are using 1.5 and putting following lines, it will not work..
    for( int id = 0 ; id < ids.length ; id++ )
out.println( id + " : " + request.getParameter( "empNO" + id ) ) ;

because you are using the counter interger (id) to make your variable name, not the actual value from the array ids.
>>
in 1.5
 for( String id : ids )
        out.println( request.getParameter( "empNO" + id ) ) ;

the variable id is a string whose value matches the individual element of array ids on everu itration...
similar to ids[id]..

in 1.4
  for( int id = 0 ; id < ids.length ; id++ )
id becomes the interger counter & not the string value of elements of ids...

I hope I was able to explain it ...:-)


0
 
LVL 35

Expert Comment

by:TimYates
ID: 17889611
I saw this, and thought it may prove useful and/or interesting :-)

http://today.java.net/pub/a/today/2006/11/07/nuances-of-java-5-for-each-loop.html
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

609 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