Skip to Content
author's profile photo
Former Member

Radio button group client side javascript

Hi,

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

Markandeya

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • author's profile photo
    Former Member
    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

    <%

    // -


    JSP-scriptlet-START----


    // 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);

    // -


    JSP-scriptlet-END----


    %>

    </hbj:radioButtonGroup>

    </hbj:form>

    <script language="JavaScript">

    // -


    JAVASCRIPT-START----


    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';

    // -


    JAVASCRIPT-END----


    </script>

    </hbj:page>

    </hbj:content>

    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

      Markandeya