Solved

checked value problem in radio button

Posted on 2006-11-12
4
240 Views
Last Modified: 2010-04-01
i give radio button name for all;i can't give different name for all rado buttons. if i check one radio button it should fetch me checked
employeeNo value;

<%

String test[] =request.getParameterValues("test");

System.out.println("kk");
if(test != null && test.length > 0)
{
for(int i=0;i<test.length;i++)
      {

      }
}
%>

<html>
<head>
<script language="javascript">
<!--

function getSelected(radioObj){
  for(var i = 0; i < radioObj.length; i++){
    if(radioObj[i].checked){
        document.forms[0].test[i].value=radioObj[i].value;
        alert(document.forms[0].test[i].value)
    }
  }

}

//-->
</script>
</head>
<body>
<form action="example.jsp">
<input type="radio" name="test" value="a" onclick="getSelected(this.form.test);">A<br>
<input type="hidden" name="employeeNo0" value="1">

<input type="radio" name="test" value="b" onclick="getSelected(this.form.test);">B<br>
<input type="hidden" name="employeeNo1" value="2">

<input type="radio" name="test" value="c" onclick="getSelected(this.form.test);">C<br>
<input type="hidden" name="employeeNo2" value="3">

<input type="radio" name="test" value="d" onclick="getSelected(this.form.test);">D<br>
<input type="hidden" name="employeeNo3" value="4">

<input type="submit" value="submit" >

</form>
</body>
</html>
0
Comment
Question by:chaitu chaitu
  • 2
4 Comments
 
LVL 10

Expert Comment

by:jaggernat
ID: 17927611
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 17927892
i want corresponding employeeNo value in jsp;
0
 
LVL 10

Expert Comment

by:jaggernat
ID: 17932373
your bean would hold the "selected" radion button value and you will have to get it from the getTest( ) in the  bean.
0
 
LVL 9

Accepted Solution

by:
ftaco96 earned 500 total points
ID: 17933299
Try this...

String test =request.getParameter("test");
String employeeNo = request.getParameter("employeeNo" + test);


and the HTML would look like this...

<input type="radio" name="test" value="a" onclick="getSelected(this.form.test);">A<br>
<input type="hidden" name="employeeNoa" value="1">

<input type="radio" name="test" value="b" onclick="getSelected(this.form.test);">B<br>
<input type="hidden" name="employeeNob" value="2">

<input type="radio" name="test" value="c" onclick="getSelected(this.form.test);">C<br>
<input type="hidden" name="employeeNoc" value="3">

<input type="radio" name="test" value="d" onclick="getSelected(this.form.test);">D<br>
<input type="hidden" name="employeeNod" value="4">


--- OR ---

Why not just do this?

<input type="radio" name="employeeNo" value="1" onclick="...">A<br>

<input type="radio" name="employeeNo" value="2" onclick="...">B<br>

<input type="radio" name="employeeNo" value="3" onclick="...">C<br>

<input type="radio" name="employeeNo" value="4" onclick="...">D<br>


and the JSP would look like this...

String employeeNo = request.getParameter("employeeNo");
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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
servlet init param and contect param 3 68
main method of string class 3 122
throw exception 21 67
Unhandled exception type Exception 18 52
This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…

749 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