By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

How to create a RADIO button using DOM

P: n/a

Can any one help me, how to create a Radio button using DOM with default
one option is selected

Thanks in advance

Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Raghuram Banda wrote:

Can any one help me, how to create a Radio button using DOM with default
one option is selected

Thanks in advance

The following compliant, validated and tested code will work flawlessly,
impeccably in Opera 7.20, NS 7.1 and Mozilla 1.5b. MSIE 6 for windows
will create the radio buttons and labels but checking the radio buttons
won't work: this is due to a current DOM-tree-modification limitation in
that browser.

Javascript and Browser bugs:
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


<html lang="en-us">


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title>Dynamically created radio buttons</title>

<style type="text/css">
body {margin:16px; color:black; background-color:white;}

<script type="text/javascript">
var arrData = [["0", "Man"],["1", "Woman"],["2", "Monkey"]];
function addGroup3Radio()
var objDiv = document.getElementById("idDiv");
for (var i=0; i < arrData.length; i++)
var objRadItem = document.createElement("input");
objRadItem.type = "radio"; = "radGroup"; = "idrad_" + i;
objRadItem.value = arrData[i][0];

if(i == 1) {objRadItem.defaultChecked = true; objRadItem.checked = true; };

var objTextNode = document.createTextNode(" " + arrData[i][1]);

var objLabel = document.createElement("label");
objLabel.htmlFor =;

var objBreak = document.createElement("br");

document.forms["FirstFormName"].cmdAdd.disabled = true;


<form name="FirstFormName" action="">
<input type="button" name="cmdAdd" value="Add a group of 3 radio
buttons" onclick="addGroup3Radio();">

<form name="SecondFormName" action="">
<div id="idDiv"></div>


Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.