Solved

checked value problem in radio button

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
Use of TCL script on Cisco devices:  - create file and merge it with running configuration to apply configuration changes
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
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.

760 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

20 Experts available now in Live!

Get 1:1 Help Now