cancel
Showing results for 
Search instead for 
Did you mean: 

Radio button group client side javascript

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

<%@ 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>

Former Member
0 Kudos

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