[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

WHEN PAGE SUBMITS how to retrieve checked value in servlet;;selected radio button value should come in servlet

Posted on 2006-10-30
9
Medium Priority
?
455 Views
Last Modified: 2011-09-20
for(int i=0;i<list.size();i++)
{
<td><input type="radio" id="empCheck<%=i%>" name="empCheck" onClick="selectEmp('<%=empHeader.empId%>',<%=i%>)"></td>
<td><input type=hidden id='empId<%=i%>' name="empId" value='<%= empHeader.empId%>'> </td>
}
function selectEmp(refId,i)
{
     
     if(document.getElementById('empCheck'+i).checked)
          document.getElementById('empId'+i).value=refId;
     else
          document.getElementById('empId'+i).value="";    
     var len=document.forms[0].empId.length;

   for(var i=0;i<len;i++)
   {
    if(document.forms[0].empId[i].checked  == true)  
    document.getElementById('empId'+i).value=refId;
   }

   
}

function ex()
                        {
                        Url      =      'empservlet';
                              document.forms[0].action = Url;
                        
                        document.forms[0].submit();
                        }

<input type="button" name="b1" VALUE="submit" class = 'input' onClick="ex()">

                        
WHEN PAGE SUBMITS how to retrieve checked value in servlet;;selected radio button value should come in servlet.

if i use request.getParameter("empId") then " " is coming and if i use request.getParameterValues("empId") all values r coming instead of checked one.



see this another sample jsp;

second_page.jsp

from the DB iterate the loop and display the results.presently i hardcoded the values.

when user clicked particular radio button its empId and corresponding empseqno values should come ..

<script>

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

<form action="second_page.jsp" method="post">
<table border="0" width="820" cellpadding="2" cellspacing="1" >
<tr class='formheader' align=center>
<td>
<input type="radio" id="empId" name="empId" value="11111">111111
<input type="hidden" id="empseqno" name="empseqno" value="aaaa">
</td>
</tr>
<tr class='formheader' align=center>
<td>
<input type="radio" id="empId" name="empId" value="222222">22222
<input type="hidden" id="empseqno" name="empseqno" value="bbbb">
</td>
</tr>

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

</form>


At second_page.jsp, you do this to retrieve and display:

<%
out.println(request.getParameter("empId"));
out.println(request.getParameter("empseqno"));

%>


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
  • 4
  • 3
  • 2
9 Comments
 
LVL 9

Expert Comment

by:matthew016
ID: 17838321
Use attribute value in your html :

<input value="M" name="gender" type="radio">Male
<input value="F" name="gender" type="radio">Female

And in your servlet the usual thing :

String sexe = request.getParameter("gender");

U will retrieve the value of attribute value

0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 17839842
see this another sample jsp;



from the DB iterate the loop and display the results.presently i hardcoded the values.

when user clicked particular radio button its empId and corresponding empseqno values should come ..

second_page.jsp
*************
<script>

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

<form action="second_page.jsp" method="post">
<table border="0" width="820" cellpadding="2" cellspacing="1" >
<tr class='formheader' align=center>
<td>
<input type="radio" id="empId" name="empId" value="11111">111111
<input type="hidden" id="empseqno" name="empseqno" value="aaaa">
</td>
</tr>
<tr class='formheader' align=center>
<td>
<input type="radio" id="empId" name="empId" value="222222">22222
<input type="hidden" id="empseqno" name="empseqno" value="bbbb">
</td>
</tr>

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

</form>


At second_page.jsp, you do this to retrieve and display:

<%
out.println(request.getParameter("empId"));
out.println(request.getParameter("empseqno"));

%>
0
 
LVL 9

Expert Comment

by:matthew016
ID: 17840986
the value of empId is ok now ?
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 20

Author Comment

by:chaitu chaitu
ID: 17841160
its ok but corresponding empseqno how will i get??
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 17844585
you will have to change the names of hidden fields as well, otherwise you will keep on getting all the values..

<form action="second_page.jsp" method="post">
<table border="0" width="820" cellpadding="2" cellspacing="1" >
<tr class='formheader' align=center>
<td>
<input type="radio" id="empId1" name="empId1" value="11111">111111
<input type="hidden" id="empseqno1" name="empseqno1" value="aaaa">
</td>
</tr>
<tr class='formheader' align=center>
<td>
<input type="radio" id="empId2" name="empId2" value="222222">22222
<input type="hidden" id="empseqno2" name="empseqno2" value="bbbb">
</td>
</tr>

in your servlet
if(request.getParemeter("empId1")!=null)
request.getParameter("empseqno2");
you can get all the parameter names in a enumeration and iterate it thru to make it generic
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 17847865
how do i know that which radio button value is clicked??

execute the below sample jsp;

this is a sample jsp ;when i select one radio button and enter submit how to capture the empNO to the corresponding empId;

<script>

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

<form action="second_page.jsp" method="post">
<table border="0" width="820" cellpadding="2" cellspacing="1" >

<%
for(int i=0;i<10;i++)
{%>
<tr class='formheader' align=center>
<td>
<input type="radio" 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>


At second_page.jsp, you do this to retrieve and display:

<%
out.println(request.getParameter("empId"));
out.println(request.getParameter("empNO"));

%>

0
 
LVL 19

Accepted Solution

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

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

</form>


At second_page.jsp, you do this to retrieve and display:

<%
for(int i=0;i<10;i++)
{
if(request.getParameter("empId"+i)!=null)
{
out.println(request.getParameter("empId"+i));
out.println(request.getParameter("empNO"+i));
}
}

%>
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 17849292
with the above code i will get all empid's not exactly checked one
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 17849302
unless the radio button is checked, the value is not sent to the server... so rest all you empid values will be null... thats why I have placed that if condition in the loop
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Sometimes Administrators rights are not enough. These cases call for the SYSTEM account. The process in this article outlines the steps required to execute commands using the SYSTEM account.
An overview of cyber security, cyber crime, and personal protection against hackers. Includes a brief summary of the Equifax breach and why everyone should be aware of it. Other subjects include: how cyber security has failed to advance with technol…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
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

656 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