473,775 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamicaly creating radio button does not work in IE

sam
Hi all,
I am dynamically creating a table rows and inerting radio buttons which
are also dynamically created. Everything works fine in Firefox as
expected. But I am not able to select radio buttons in IE. It does not
even throw any errors. I have searched over the net but could not find
anyhelp. Hope some experts here could help me.
Here is part my code that dynamically generates the radio buttons, I
cannot paste the entire code as it is very huge.

var n = 0;
var row = table.insertRow (table.rows.len gth);
var cell = row.insertCell( row.cells.lengt h);

cell = row.insertCell( row.cells.lengt h);
var radio = document.create Element('input' );
radio.setAttrib ute('type', 'radio');
radio.setAttrib ute('name', 'test'+n);
radio.setAttrib ute('value', 'test123');
radio.setAttrib ute('onclick', "this.form['test"+n+"'].disabled =
true;");
cell.appendChil d(radio);
cell = row.insertCell( row.cells.lengt h);

Any help really aprreciated.

thanks,
Sam

Mar 15 '06 #1
5 12553
sam wrote :
Hi all,
I am dynamically creating a table rows and inerting radio buttons which
are also dynamically created. Everything works fine in Firefox as
expected. But I am not able to select radio buttons in IE.
You mean check radio buttons.

It does not even throw any errors.
When you seek help, it is always best to provide an url along with the
message text of the javascript error being reported.
I have searched over the net but could not find
anyhelp. Hope some experts here could help me.
Here is part my code that dynamically generates the radio buttons, I
cannot paste the entire code as it is very huge.

var n = 0;
var row = table.insertRow (table.rows.len gth);
You may want to consider -1 instead of requiring the browser to
calculate the table.rows.leng th. What you do though (using
table.rows.leng th) is more self-explanatory, intuitive, helps code
maintenance.

var objTRow = table.insertRow (-1);
"If index is -1 or equal to the number of rows, the new row is appended."
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-39872903

var cell = row.insertCell( row.cells.lengt h);
var objTCell = row.insertCell(-1);

"If index is -1 or equal to the number of cells, the new cell is appended."
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-68927016

cell = row.insertCell( row.cells.lengt h);
You have twice the same assignment here.
var radio = document.create Element('input' );
radio.setAttrib ute('type', 'radio');
MSIE 6 is DOM 1 (HTML interface) compliant but is not DOM 2 compliant.

http://www.w3.org/TR/2000/WD-DOM-Lev...tml#ID-6043025

http://www.w3.org/TR/DOM-Level-2-HTM...tml#ID-6043025

Type was read-only in DOM 1; this was changed in DOM 2.
radio.setAttrib ute('name', 'test'+n);
One other thing: you should prefer DOM 2 HTML interface methods instead
of using setAttribute since setAttribute is less widely supported in
browsers or is less buggy.
radio.setAttrib ute('value', 'test123');
radio.setAttrib ute('onclick', "this.form['test"+n+"'].disabled =
true;");
This is likely not to succeed. Event attributes are not set that way.
Instead:

radio.onclick = new Function("evt", "this.form['test"+n+"'].disabled =
true;")
cell.appendChil d(radio);
cell = row.insertCell( row.cells.lengt h);

Any help really aprreciated.

thanks,
Sam


Dynamically create dynamically radio buttons
http://www.gtalbot.org/DHTMLSection/...ioButtons.html

Please read my copyright notice:
http://www.gtalbot.org/Varia/CopyrightNotice.html

MSIE 6 bug: Dynamically inserted radio button is not checkable
http://www.gtalbot.org/BrowserBugsSe...dioButton.html

which I have reported already to MSIE 7 dev. team.

Gérard
--
remove blah to email me
Mar 15 '06 #2
sam said on 15/03/2006 10:26 AM AEST:
Hi all,
I am dynamically creating a table rows and inerting radio buttons which
are also dynamically created. Everything works fine in Firefox as
expected. But I am not able to select radio buttons in IE. It does not
You can have a radio button in the source HTML that is hidden (say set
its display attribute to 'none') and then clone it whenever you want to
add other.

even throw any errors. I have searched over the net but could not find
anyhelp. Hope some experts here could help me.
Here is part my code that dynamically generates the radio buttons, I
cannot paste the entire code as it is very huge.

var n = 0;
var row = table.insertRow (table.rows.len gth);
var cell = row.insertCell( row.cells.lengt h);

cell = row.insertCell( row.cells.lengt h);
var radio = document.create Element('input' );
Somewhere in your HTML source put:

<input type="radio" id="baseRadioBu tton" style="display: none;">

Then (with appropriate feature testing) clone it as required:

var radio =
document.getEle mentById('baseR adioButton').cl oneNode(false);

radio.style.dis play = '';

radio.setAttrib ute('type', 'radio');
radio.setAttrib ute('name', 'test'+n);
radio.setAttrib ute('value', 'test123');
radio.setAttrib ute('onclick', "this.form['test"+n+"'].disabled =
true;");
And then (remember to change the ID):

radio.id = 'test' + n;
radio.name = 'test' + n;
radio.value = 'test123';
radio.onclick = new Function(
'this.form["test' + n + '"].disabled = true;');

cell.appendChil d(radio);
cell = row.insertCell( row.cells.lengt h);

Any help really aprreciated.

thanks,
Sam


--
Rob
Mar 15 '06 #3


For IE, do it by means of property, setAtrribute() is correct,
however IE has issues with setAttribute() :/ , use instead,
radio.type=..; radio.onclick=. ..;
Danny
Mar 15 '06 #4
> "sam" <za*****@gmail. com> wrote:
news:11******** **************@ v46g2000cwv.goo glegroups.com.. ..

Hi all,
I am dynamically creating a table rows and inerting radio buttons
which are also dynamically created. Everything works fine in
Firefox as expected. But I am not able to select radio buttons in
IE. It does not even throw any errors. I have searched over the net
but could not find anyhelp. Hope some experts here could help me.
Here is part my code that dynamically generates the radio buttons, I
cannot paste the entire code as it is very huge.

[snip]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content=
"text/html; charset=windows-1252">
<!--[if IE]>
<script type="text/javascript">
var IE=1;
</script>
<![endif]-->
<script type="text/javascript">
var n=0;
function addRadio(){
var i=0;
while(i<5){
if(typeof(IE)== 'number'){
j=document.crea teElement('<inp ut name=" ">');
}
else {
j=document.crea teElement('inpu t');
}
j.name='willy';
j.type='radio';
j.value=++n;
document.body.a ppendChild(j);
label=document. createElement(' label');
j.id=label.html For='willy'+n;
label.appendChi ld(document.cre ateTextNode('wi lly'+n));
document.body.a ppendChild(labe l);
document.body.a ppendChild(docu ment.createElem ent('br'));
i++;
}
}
</script>
<title></title>
</head>
<body>
<p><button onclick="addRad io()">Add Radio button</button></p>
</body>
</html>

--
BootNic Wednesday, March 15, 2006 2:59 AM

"I suppose they are vicious rascals, but it scarcely matters what
they are. I'm after what they know."
*Gibson-Sterling, The Difference Engine*

Mar 15 '06 #5
sam
Thanks to one and all who responded .. All the answers really helped me
inprove my code and now it works in IE as well..

Thanks,
Sam

Mar 16 '06 #6

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

Similar topics

6
18831
by: HD | last post by:
Hi. I have an asp page with radio buttons and a combobox... when the user clicks a radio button, I want the form to submit so I can execute the ASP code in order to change the list shown in the combobox... I have 2 radiobuttons: <input type="radio" name="terriprod" value="E">E <input type="radio" name="terriprod" value="D">D I have tried adding an OnClick event to each of the radio button...
3
2832
by: lee | last post by:
Hello I need some javascript code I've written to handle 2 values from an HTML form. I've been successful using the "label" attribute (I've simplied the example below): <input type="radio" name="group1" value="3" label="Cheese" checked>Cheese<br>
2
3990
by: Bisser Milanov | last post by:
I add radio buttons created dynamically in a datagrid on each row of the grid. When I see the generated HTML I see that in front of each name for a radio button is added: name="_ctl0:_ctl1:_ctl3: and this is unique for each radio button. So they are never in the same group. How can I put them in the same group?
0
1321
by: MarkusPoehler | last post by:
I have several classic ASP projects running on Webserver. I would like to implement some .net functionalities. Because I need the references I have to "upgrade" the existing ones wit a new .net webproject. I've made some tests but it does not work. If I setup a new Webproject and define e.g. http://server1/web1 to store the project, it fails creating. Creating new projects into folders that don't exist also fails. Creating Web...
2
3493
by: NishSF | last post by:
Would anyone have any suggestions/javascript code so that if one clicks the Radio Button "Yes" below he has the option of selecting any of the six CheckBox below. If the user clicks on Radio Button "No", he should not have the option of clicking on any of the six checkboxes. See Code attached. Thank you so much in advance for your help as I can't get to make this combo work. <p>Did you have any problems finding any of the information...
2
1697
by: epigram | last post by:
I'm dynamically creating a number of radio buttons on my aspx page based upon data read from a db. Each radio button has autopostback turned on. I'm experiencing two problems. 1) I am reading the db, creating the radio buttons, and setting the checked property (also based upon data in the db) in Page_Load regardless of whether a postback is occurring or not. The page loads and displays correctly each time unless the database is updated...
8
4685
by: stefano | last post by:
HI, I have aproblem with XHTML radio button. <form name=" form"> <input name="radio" type="radio" onclick="return false" /> <input name="radio" type="radio" onclick="return false" /> <input name="radio" type="radio" onclick="return false" /> </form> I want that when the radio is clicked, it is not checked. in other word I want the click has no effect on the radio.
5
2725
by: swatidesai0407 | last post by:
hi im validating radio buttons i create dis radio button in php based on some how many records of my query. i wrote a javascript to validate this buttons. wat i do is dat wen no radio button are selected it should giv message dat select a radio button. else it should go to other page. My code works fine when there are more than 1 radio button but when only 1 radio button is der dat time it does not work
11
2278
by: Twayne | last post by:
Hi, Newbie to PHP here, no C or other relevant background, so pretty niave w/r to the nuances etc. but I think this is pretty basic. XP Pro, SP2+, PHP 4.4.7, XAMPP Local Apache Server 6.something I think and running as a service, Using NoteTab Pro as an IDE (works well). If you need more, just ask. In one functioning form:
0
9622
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10107
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
10048
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
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7464
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
6718
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();...
0
5486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2853
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.