473,594 Members | 2,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 createRadioButt on(){
var newRadioButton = document.create Element("<INPUT TYPE='RADIO'
NAME='RADIOTEST ' VALUE='First Choice'>")
alert(newRadioB utton);
document.getEle mentById("mtwri te").appendChil d(newRadioButto n);
}
</SCRIPT>

</HEAD>

<BODY>
<INPUT TYPE="BUTTON" ONCLICK="create RadioButton()" VALUE="Create two
Radio Buttons"><BR>
<table><tr><t d 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 1421
On 18 Jan 2004 14:49:35 GMT, Mark <an*******@devd ex.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.******@blueyo nder.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*******@devd ex.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 createRadioButt on(){
var newRadioButton = document.create Element("<INPUT TYPE='RADIO'
NAME='RADIOTEST ' VALUE='First Choice'>")
alert(newRadioB utton);
document.getEle mentById("mtwri te").appendChil d(newRadioButto n);
}
</SCRIPT>

</HEAD>

<BODY>
<INPUT TYPE="BUTTON" ONCLICK="create RadioButton()" VALUE="Create two
Radio Buttons"><BR>
<table><tr><t d 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 DynamicallyCrea te2RadioButtons ()
{
var LabelFirstInput = document.create Element("label" );
var LabelSecondInpu t = document.create Element("label" );
if(document.all && !window.opera && document.create Element)
{
var FirstInput = document.create Element("<input type='radio'
name='radiotest ' id='idFirstInpu tRadio' value='first choice'>");
var SecondInput = document.create Element("<input type='radio'
name='radiotest ' id='idSecondInp utRadio' value='second choice'>");
}
else if(document.cre ateElement && document.create TextNode)
{
var FirstInput = document.create Element("input" );
var SecondInput = document.create Element("input" );
FirstInput.type = SecondInput.typ e = "radio";
FirstInput.name = SecondInput.nam e = "radiotest" ;
FirstInput.id = "idFirstInputRa dio";
SecondInput.id = "idSecondInputR adio";
FirstInput.valu e = "first choice";
SecondInput.val ue = "second choice";
}
else
{
return
};
LabelFirstInput .appendChild(Fi rstInput);
LabelFirstInput .htmlFor = "idFirstInputRa dio";
LabelFirstInput .appendChild(do cument.createTe xtNode("First option"));
document.forms[0].childNodes[0].appendChild(La belFirstInput);

document.forms[0].childNodes[0].appendChild(do cument.createEl ement("br"));

LabelSecondInpu t.appendChild(S econdInput);
LabelSecondInpu t.htmlFor = "idSecondInputR adio";
LabelSecondInpu t.appendChild(d ocument.createT extNode("Second option"));
document.forms[0].childNodes[0].appendChild(La belSecondInput) ;
}

HTML
----
<body onload="Dynamic allyCreate2Radi oButtons();">
<form action=""><p></p></form>

DU
Jul 20 '05 #4
DU
Michael Winter wrote:
On 18 Jan 2004 14:49:35 GMT, Mark <an*******@devd ex.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
2837
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 Tkinter import * class GetVariant: def __init__(self): self.root = Tk()
0
4124
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 BindChain() Sub for the line: AddHandler Rb.CheckedChanged, AddressOf BindAssembly_Click
3
36172
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 rewrite it so that it's W3C compliant. Reading through earlier messages I concluded I should go with getElementById but this doesn't work. What am I doing wrong? Your help is much appreciated.
1
4037
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 can be true). So I've created a class inheriting from DataGridColumnStyle and added the following code to the class: protected RadioButton rb ; ....
3
7227
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 a postback. I only want to do a postback if the value of the radiobutton is changed. What is the best method to accomplish this? thx dave
2
2934
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: "'<%#((OnlineLearningEnvironment.MultipleChoiceChoice)Container.DataItem).choiceText%>' is not a valid identifier." So, my question is, what do I do? (Code follows) Thank you in advance,
3
3061
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 ascx-control itself creates dynamically many radiobuttons in this way: foreach (DataRow radiobutton_item in rbl_values.Rows) { RadioButton single_radiobutton = new RadioButton(); single_radiobutton.ID = "idname"; single_radiobutton.GroupName =...
4
1601
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 Integer For n = 0 To 2 rb(n) = New RadioButton rb(n).Text = "Text: " + CStr(n)
5
11639
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 click to select one of the radiobuttons to select. The default behavior of Focus() seems to also select the radiobutton, but I can't seem to find what is causing this to happen. I would like very much to seperate the Focus and the selection....
8
44025
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 checked. In VB.Net if I enclose a group of radiobuttons in a groupbox control - I get the single checked radiobutton behavior, but the groupbox does not seem to return the index of the checked radiobutton. Is there a way to get the groupbox...
0
7880
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8255
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8010
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8242
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5413
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1486
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.