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
430 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
  • 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
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 17841160
its ok but corresponding empseqno how will i get??
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java.lang.UnsupportedClassVersionError 8 372
Apache server configuration 7 80
default methods vs abstract class 1 109
spring JDBC Template example error 26 206
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now