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
427 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
logging jar 1 104
jersey maven project error 7 134
java beans and EJBs 5 182
JavaScript parse form with colon separated values 2 61
HOW TO: Install and Configure VMware vSphere Hypervisor 6.5 (ESXi 6.5), Step by Step Tutorial with screenshots. From Download, Checking Media, to Completed Installation.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
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…

707 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

15 Experts available now in Live!

Get 1:1 Help Now