Solved

checked value problem in radio button

Posted on 2006-11-12
4
233 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tomcat users xml 7 120
Multiple Images Upload [JSP Web-application] 3 38
How to find missing packages when using Netbeans IDE 8.1 ? 19 54
runtime exception 2 28
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Data breaches are on the rise, and companies are preparing by boosting their cybersecurity budgets. According to the Cybersecurity Market Report (http://www.cybersecurityventures.com/cybersecurity-market-report), worldwide spending on cybersecurity …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

772 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