Why won't the radio button get checked?

R

Ray

Hi there,

I have a table, each row of which contains 5 radiobuttons that the user
uses to specify a rating. From radio button to my object, no problem
there. However when I want to populate the radiobuttons with the
correct value, somehow they are not checked. Any idea why?

var ratingTd = document.createElement('TD');
for(var c = 1; c <= 5; c++) {
var ratingText = "<input type=\"radio\" name=\"eventRating" + index
+ "\" value=\"" + c +"\">";
var newCb = document.createElement(ratingText);
if(("" + c) == item.rating) {
newCb.checked = true;
}
var span = document.createElement('span');
span.appendChild(newCb);
span.appendChild(document.createTextNode(c));
ratingTd.appendChild(span);
}
row.appendChild(ratingTd);

I've stepped through the debugger to see that yes, the code
newCb.checked=true gets called according to the correct rating. But in
the rendered screen none of the buttons are ever checked. Why would
that be, I wonder?

Thanks
Ray
 
R

Ray

Ray said:
I have a table, each row of which contains 5 radiobuttons that the user
uses to specify a rating. From radio button to my object, no problem
there. However when I want to populate the radiobuttons with the
correct value, somehow they are not checked. Any idea why?
<snip>

Nevermind, turned out I came across an IE bug, sigh. Instead of this:

if(("" + c) == item.rating) {
newCb.checked = true;
}

I should've done this:

if(("" + c) == item.rating) {
newCb.checked = true;
newCb.defaultChecked = true;
}

Thanks
Ray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top