473,554 Members | 3,068 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 12538
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
18817
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...
3
2792
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
3965
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
1314
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...
2
3467
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...
2
1683
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...
8
4677
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...
5
2713
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...
11
2258
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
7596
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...
0
7519
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...
0
7798
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. ...
0
8039
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...
0
7887
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...
0
3545
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2015
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
1130
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
838
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...

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.