<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-us">
<head>
<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 test, works in IE, not in anything else?</title>
<script>
// Start of loadXMLDoc()
function loadXMLDoc(dname)
{
// Variables
var xmlDoc;
// code for IE
if (window.ActiveXObject){xmlDoc=new ActiveXObject("Microsoft.XMLDOM");}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument){xmlDoc=document.implementation.createDocument("","",null);}
else{alert("Your browser cannot handle this script");}
xmlDoc.async=false;
xmlDoc.load(dname);
return(xmlDoc);
}
// End of loadXMLDoc()
// Start of displayCurrentPoll()
function displayCurrentPoll()
{
// Variables
var idRadio,typeRadio,onclickRadio;
var elementID, newRadio, newLabel, option, question;
var radio=new Array();
var label=new Array();
var space=new Array();
var i;
// Sets the attributes that are constant for all new elements
typeRadio='radio';
onclickRadio='updatePoll()';
// Load the xml file
xmlDoc=loadXMLDoc("poll.xml");
// Locate the xml elements
question=xmlDoc.getElementsByTagName('question');
option=xmlDoc.getElementsByTagName('option');
// Locate the place for the poll
elementID=document.getElementById('CurrentPoll');
// Write the question
label[0]=document.createElement('label');
space[0]=document.createElement('br');
label[0].htmlFor="Label";
label[0]=document.createTextNode(question[0].childNodes[0].nodeValue);
space[0].id ='Break';
elementID.appendChild(label[0]);
elementID.appendChild(space[0]);
// Create one radio button for each of the options
for (i=1;i<5;i++)// The value for the max times is hardcoded for now, except that to change
{
radio[i]=document.createElement('input');
label[i]=document.createElement('label');
space[i]=document.createElement('br');
radio[i].type= typeRadio;
radio[i].id='Radio';
radio[i].value='Choice';
radio[i].onclick=onclickRadio;
label[i].htmlFor='Label';
label[i]=document.createTextNode(option[0].childNodes[i-1].childNodes[0].nodeValue);
space[i].id ='Break';
elementID.appendChild(radio[i]);
elementID.appendChild(label[i]);
elementID.appendChild(space[i]);
}
}// End of displayCurrentPoll()</script>
</head>
<body onload="displayCurrentPoll();">
<div>
<form id="CurrentPoll"></form>
</div>
</body>
</html>
|