Mark wrote:
Hi - my code below works in IE6, but not in NN7 - I thought it was using
the correct standards,
No. It uses a dedicated workaround for MSIE 6.
but could anyone please tell me where I'm going wrong?
Your code is not using valid markup to start with.
Thanks, Mark
<HTML>
<HEAD>
<SCRIPT>
function createRadioButton(){
var newRadioButton = document.createElement("<INPUT TYPE='RADIO'
NAME='RADIOTEST' VALUE='First Choice'>")
alert(newRadioButton);
document.getElementById("mtwrite").appendChild(new RadioButton);
}
</SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE="BUTTON" ONCLICK="createRadioButton()" VALUE="Create two
Radio Buttons"><BR>
<table><tr><td id="mtwrite"></td></tr></table>
<BODY>
</HTML>
The following will work in NS 7.1, Mozilla 1.6, Opera 7.50 and MSIE 6
for windows. The code was tested on these browsers in a XHTML 1.0 strict
webpage.
javascript
:
-----------
function DynamicallyCreate2RadioButtons()
{
var LabelFirstInput = document.createElement("label");
var LabelSecondInput = document.createElement("label");
if(document.all && !window.opera && document.createElement)
{
var FirstInput = document.createElement("<input type='radio'
name='radiotest' id='idFirstInputRadio' value='first choice'>");
var SecondInput = document.createElement("<input type='radio'
name='radiotest' id='idSecondInputRadio' value='second choice'>");
}
else if(document.createElement && document.createTextNode)
{
var FirstInput = document.createElement("input");
var SecondInput = document.createElement("input");
FirstInput.type = SecondInput.type = "radio";
FirstInput.name = SecondInput.name = "radiotest";
FirstInput.id = "idFirstInputRadio";
SecondInput.id = "idSecondInputRadio";
FirstInput.value = "first choice";
SecondInput.value = "second choice";
}
else
{
return
};
LabelFirstInput.appendChild(FirstInput);
LabelFirstInput.htmlFor = "idFirstInputRadio";
LabelFirstInput.appendChild(document.createTextNod e("First option"));
document.forms[0].childNodes[0].appendChild(LabelFirstInput);
document.forms[0].childNodes[0].appendChild(document.createElement("br"));
LabelSecondInput.appendChild(SecondInput);
LabelSecondInput.htmlFor = "idSecondInputRadio";
LabelSecondInput.appendChild(document.createTextNo de("Second option"));
document.forms[0].childNodes[0].appendChild(LabelSecondInput);
}
HTML
----
<body onload="DynamicallyCreate2RadioButtons();">
<form action=""><p></p></form>
DU