Prev: I.E. jscript error: 'document.getElementById(...)' is null or not an object.
Next: help - onChange and Confirm
From: David Mark on 17 Jan 2008 17:25 On Jan 15, 8:15 am, SAM <stephanemoriaux.NoAd...(a)wanadoo.fr.invalid> wrote: > HugeBob a écrit : > > > The following works in FF and doesn't in IE: > > > var radioCell1 = document.createElement("td"); > > var radioButton1 = document.createElement("input"); > > radioButton1.type = "radio"; > > that here doesn't work in my IE Mac ('type' is reserved :-( ) > > > radioButton1.name = "someName"; > > radioButton1.value = "someValue"; > > if (defaultArg1 == radioButton1.value) > > radioButton1.checked = true; > > here you must append the td, then append ist content (I belive) > > > radioCell1.appendChild(radioButton1); > > > The radio button is created and visible. But, when you click on them, > > nothing happens: i.e., they don't hold a checked state. They don't > > even go black. Can you suggest a good reference book for this? > > perhaps also change the order : > > var radioCell1 = document.createElement("td"); > var radioButton1 = document.createElement("input"); > radioButton1.type = "radio"; > > // supposing myTbody.myRow is the targeted TR > myTbody.myRow.appendChild(radioCell1); > > radioCell1.appendChild(radioButton1); > radioButton1.name = "someName"; > radioButton1.value = "someValue"; > if (defaultArg1 == radioButton1.value) > radioButton1.checked = true; > Order is everything when creating radio buttons in IE. The type is assigned after the name and only after the element has been appended to a parent element. Then they will work and show up in the elements collection of the form.
From: HugeBob on 18 Jan 2008 15:17 On Jan 17, 5:25 pm, David Mark <dmark.cins...(a)gmail.com> wrote: > Order is everything when creating radio buttons in IE. The type is > assigned after the name and only after the element has been appended > to a parent element. Then they will work and show up in the elements > collection of the form. Hi All, Thanks for your suggestions. I tried two methods: Method 1: newHTMLTableRow.appendChild(rowLabelCell); var radioCell1 = document.createElement("td"); var radioButton1 = document.createElement("input"); radioButton1.name = nameArg; radioButton1.type = "radio"; radioCell1.appendChild(radioButton1); newHTMLTableRow.appendChild(radioCell1); radioCell1.align = "center"; radioButton1.value = valueArg; if (defaultArg1 == radioButton1.value) radioButton1.checked = true; Method II: newHTMLTableRow.appendChild(rowLabelCell); var radioCell1 = document.createElement("td"); var radioButton1 = document.createElement("input"); radioButton1.name = nameArg; newHTMLTableRow.appendChild(radioCell1); radioButton1.type = "radio"; radioCell1.appendChild(radioButton1); radioCell1.align = "center"; radioButton1.value = valueArg; if (defaultArg1 == radioButton1.value) radioButton1.checked = true; Now the radio buttons are holding their *.checked values. But, I'm still not able to alter their states manually.
From: David Mark on 18 Jan 2008 15:47 On Jan 18, 3:17 pm, HugeBob <rnu...(a)gmail.com> wrote: > On Jan 17, 5:25 pm, David Mark <dmark.cins...(a)gmail.com> wrote: > > > Order is everything when creating radio buttons in IE. The type is > > assigned after the name and only after the element has been appended > > to a parent element. Then they will work and show up in the elements > > collection of the form. > > Hi All, > > Thanks for your suggestions. I tried two methods: > > Method 1: > > newHTMLTableRow.appendChild(rowLabelCell); > var radioCell1 = document.createElement("td"); > var radioButton1 = document.createElement("input"); > radioButton1.name = nameArg; > radioButton1.type = "radio"; > radioCell1.appendChild(radioButton1); > newHTMLTableRow.appendChild(radioCell1); > radioCell1.align = "center"; > radioButton1.value = valueArg; > if (defaultArg1 == radioButton1.value) > radioButton1.checked = true; > > Method II: > > newHTMLTableRow.appendChild(rowLabelCell); > var radioCell1 = document.createElement("td"); > var radioButton1 = document.createElement("input"); > radioButton1.name = nameArg; > newHTMLTableRow.appendChild(radioCell1); > radioButton1.type = "radio"; > radioCell1.appendChild(radioButton1); > radioCell1.align = "center"; > radioButton1.value = valueArg; > if (defaultArg1 == radioButton1.value) > radioButton1.checked = true; > > Now the radio buttons are holding their *.checked values. But, I'm > still not able to alter their states manually. Neither method is correct. As I mentioned, you must append the radio button to an element before naming it and setting its type. Try this: ... var radioButton1 = document.createElement("input"); radioCell1.appendChild(radioButton1); radioButton1.name = nameArg; radioButton1.type = "radio"; newHTMLTableRow.appendChild(radioCell1); ...
From: HugeBob on 22 Jan 2008 11:18
On Jan 22, 10:25 am, David Mark <dmark.cins...(a)gmail.com> wrote: > This looks like a similar variation of what I did. You can leave off > the slash at the end (IE will throw it away anyway.) Also, I wonder > if this solution makes the element show up in the form's elements > collection. I don't think it does. But, I'll check. When the radio buttons were showing up inactive, elements[] didn't seem to have them listed. Well, when I tried *.elements['name'].whatever, it didn't seem to work. But, now that I have the radios working, I'll give it a try again. Thanks for you help. |