Skip to Content
author's profile photo Former Member
Former Member

Radio button group client side javascript


how to know at least one radio button is checked or not under a particular radio button group using javascript at client side.

Thanks & Regards


Add comment
10|10000 characters needed characters exceeded

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on May 28, 2004 at 12:36 AM

    <%@ taglib uri= "tagLib" prefix="hbj" %>

    <%@ page import="com.sapportals.htmlb.Component" %>


    // the variables to be filled inside the htmlb form

    String radioGroupId = null;


    <hbj:content id="myContext" >

    <hbj:form id="theForm" >

    <hbj:radioButtonGroup id="radioGroup" columnCount="3" >

    <hbj:radioButton id="Radio1" text="Radio1" key="Radio1" />1

    <hbj:radioButton id="Radio2" text="Radio2" key="Radio2" />2


    // -


    // Inside each HTMLB-tag we have a variable with the same name as the

    // 'id'-attribute of the tag.

    // Thus, we have a PageContext-instance with name 'myContext',

    // since the 'hbj:content'- tag's id is 'myContext'

    // The PageContext's getParamIdForComponent(Component comp)-method returns us the

    // generated HTML-id of the given component's HTML-representation.

    radioGroupId = myContext.getParamIdForComponent(radioGroup);

    // -





    <script language="JavaScript">

    // -


    var selectedRadio;

    // get to know which radio button is checked

    if(document.getElementsByName('<%=radioGroupId%>')[0].checked) selectedRadio = 'Radio button 1 was selected';

    if(document.getElementsByName('<%=radioGroupId%>')[1].checked) selectedRadio = 'Radio button 2 was selected';

    // -





    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thank you for the detailed code,

      This has solved the problem.

      We have another requirement for checkboxe group. we used the same code but it is giving null.

      Could you please advice on how to code for ckeckboxes

      Thanks & Regards