473,385 Members | 1,312 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.

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.length);
var cell = row.insertCell(row.cells.length);

cell = row.insertCell(row.cells.length);
var radio = document.createElement('input');
radio.setAttribute('type', 'radio');
radio.setAttribute('name', 'test'+n);
radio.setAttribute('value', 'test123');
radio.setAttribute('onclick', "this.form['test"+n+"'].disabled =
true;");
cell.appendChild(radio);
cell = row.insertCell(row.cells.length);

Any help really aprreciated.

thanks,
Sam

Mar 15 '06 #1
5 12524
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.length);
You may want to consider -1 instead of requiring the browser to
calculate the table.rows.length. What you do though (using
table.rows.length) 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.length);
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.length);
You have twice the same assignment here.
var radio = document.createElement('input');
radio.setAttribute('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.setAttribute('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.setAttribute('value', 'test123');
radio.setAttribute('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.appendChild(radio);
cell = row.insertCell(row.cells.length);

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.length);
var cell = row.insertCell(row.cells.length);

cell = row.insertCell(row.cells.length);
var radio = document.createElement('input');
Somewhere in your HTML source put:

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

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

var radio =
document.getElementById('baseRadioButton').cloneNo de(false);

radio.style.display = '';

radio.setAttribute('type', 'radio');
radio.setAttribute('name', 'test'+n);
radio.setAttribute('value', 'test123');
radio.setAttribute('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.appendChild(radio);
cell = row.insertCell(row.cells.length);

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.googlegr oups.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.createElement('<input name=" ">');
}
else {
j=document.createElement('input');
}
j.name='willy';
j.type='radio';
j.value=++n;
document.body.appendChild(j);
label=document.createElement('label');
j.id=label.htmlFor='willy'+n;
label.appendChild(document.createTextNode('willy'+ n));
document.body.appendChild(label);
document.body.appendChild(document.createElement(' br'));
i++;
}
}
</script>
<title></title>
</head>
<body>
<p><button onclick="addRadio()">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
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...
3
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"...
2
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:...
0
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...
2
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...
2
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...
8
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...
5
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...
11
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...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.