473,385 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Create a RadioButton in Code for NN

Hi - my code below works in IE6, but not in NN7 - I thought it was using
the correct standards, but could anyone please tell me where I'm going
wrong?

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>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
4 1415
On 18 Jan 2004 14:49:35 GMT, Mark <an*******@devdex.com> wrote:
Hi - my code below works in IE6, but not in NN7 - I thought it was using
the correct standards, but could anyone please tell me where I'm going
wrong?


The createElement() method is supposed to receive the element name only.
You passed the entire tag.

I'm not clear (having not done it before) on how one then sets the
attributes. The two choices are altering the properties of the new Element
instance, or creating the attributes with createAttribute() and adding
them with setAttribute(). Can anyone indicate which is the most correct
way of doing it?

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
Michael Winter wrote:
On 18 Jan 2004 14:49:35 GMT, Mark <an*******@devdex.com> wrote:
Hi - my code below works in IE6, but not in NN7 - I thought it was using
the correct standards, but could anyone please tell me where I'm going
wrong?

The createElement() method is supposed to receive the element name only.
You passed the entire tag.

I'm not clear (having not done it before) on how one then sets the
attributes. The two choices are altering the properties of the new
Element instance, or creating the attributes with createAttribute() and
adding them with setAttribute(). Can anyone indicate which is the most
correct way of doing it?


Alter its properties.
There have been problems when trying to use setAttribute().

--
Randy

Jul 20 '05 #3
DU
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
Jul 20 '05 #4
DU
Michael Winter wrote:
On 18 Jan 2004 14:49:35 GMT, Mark <an*******@devdex.com> wrote:
Hi - my code below works in IE6, but not in NN7 - I thought it was using
the correct standards, but could anyone please tell me where I'm going
wrong?

The createElement() method is supposed to receive the element name only.
You passed the entire tag.


That's because this is the only known way to create and embed radio
inputs in MSIE 6. Such dedicated workaround for MSIE and way of coding
the createElement was mentioned before in this newsgroup IIRC.

I'm not clear (having not done it before) on how one then sets the
attributes. The two choices are altering the properties of the new
Element instance,
and that is the most frequent choice (and most relevant to use) one need
to use in 95% of the time. DOM 1 HTML list all assignable HTML attributes.
E.g. for form input:
http://www.w3.org/TR/DOM-Level-2-HTM...tml#ID-6043025

DU

or creating the attributes with createAttribute() and adding them with setAttribute(). Can anyone indicate which is the most
correct way of doing it?

Mike

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: VK | last post by:
Hi! What I'm missing in following code? Cannot get the values of radiobuttons. Starting only one class (GetVariant), it works. When I put two classes together, it doesn't. Regards, VK from...
0
by: rodrigo | last post by:
I have a Asp.net table control that I dynamically add rows from a SQL database. Inside the table, I add radiobuttons and they all have different ID numbers according to BindChain() Looking In...
3
by: sofie | last post by:
Hello all, I use the following javascript function in a html document to set the level of one of eight available radiobuttons. The line that's commented out works fine under IE, but I need to...
1
by: Dmitry V. Markin | last post by:
Good day! Here is my problem: I need to have a radiobutton column in my DataGrid for a representation of a bool column, where only row can be checked at one time(only one value in bool column...
3
by: dave | last post by:
I have half a dozen web form radio buttons on a web form. Each of them is set to postback=true. However, if for instance radiobutton1 is already selected and the user selects it again, it performs...
2
by: Timothy V | last post by:
Hi, I have a RadioButton within a Repeater that i wish to assign an ID dynamically to the radiobutton. However, this won't allow me due to the following error:...
3
by: visual2005beta_developer | last post by:
I have the following problem (especially with the groupname-attribut of the RadioButton-Control) when developing in Visual Studio 2005 Beta. I load an ascx-control in an aspx-page. This...
4
by: Igor | last post by:
RadioButton have property Checked (true or false). If I make RadioButtons with code, without drawing by mouse than I have problems. I write like this: Dim rb(0 To 2) As RadioButton Dim n As...
5
by: Matt B | last post by:
I know this is a bit of nonstandard behavior, but I would like the Enter key to move focus through a group of radiobuttons without selecting them. The user would then have to use Space or actually...
8
by: =?Utf-8?B?UmljaA==?= | last post by:
If you enclose a group of radiobuttons (option buttons in MS Access) in an option group control (a frame control) in Access -- the frame control will return the index of the option button that is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.