Get radio button selected value in the java jsp page


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<H1>Submitting Radio Buttons</H1>
        <FORM ACTION="ck2pge.jsp" METHOD="post">
             <INPUT TYPE="radio" NAME="radios" VALUE="radio1" CHECKED>
             Radio Button 1
            <BR>
            <INPUT TYPE="radio" NAME="radios" VALUE="radio2">
             Radio Button 2
            <BR>
            <INPUT TYPE="radio" NAME="radios" VALUE="radio3">
             Radio Button 3
            <BR>
            <INPUT TYPE="submit" VALUE="Submit">
        </FORM>
       
        <%
            if(request.getParameter("radios") != null) {
                if(request.getParameter("radios").equals("radio1")) {
                    out.println("Radio button 1 was selected.<BR>");
                }
                else {
                    out.println("Radio button 1 was not selected.<BR>");
                }
                if(request.getParameter("radios").equals("radio2")) {
                    out.println("Radio button 2 was selected.<BR>");
                }
                else {
                    out.println("Radio button 2 was not selected.<BR>");
                }
                if(request.getParameter("radios").equals("radio3")) {
                    out.println("Radio button 3 was selected.<BR>");
                }
                else {
                    out.println("Radio button 3 was not selected.<BR>");
                }
            }
        %>
</body>
</html>

No comments:

Post a Comment