Skip to Content
author's profile photo Former Member
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 a comment
10|10000 characters needed characters exceeded

Related questions

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

    <%

    // -


    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 a 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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.