I know the defaultchecked is when i enter the page, the radiobutton is checked by default.
but the radio button can't let the user choose either of them.
when the user click on 1st radio button, then checked this button, and set the 2nd radio button checked to false.
if 2nd button is checked, then set the first button checked to false.
only one of them checked.
but now when i code rad1.defaultchecked=true, it is always true, even i click another button, it can't change the checked value to the button clicked.
This code works fine with me; I have tested it on Mozilla Firefox 3.6.3 and Internet Explorer 8
Can you let us know which browser(along with version) are you testing it on?
The Next Best Thing To Knowing Something Is Knowing Where To Find It.
This is a bug in IE7. Basically in IE7 the browser doesn't generate the name attribute for radio button when its created dynamically.
To check that, just open the HTML file in your IE7 browser and after the file is loaded just type in address bar(in one line):
Now you can observe in the alert that the radio input element doesn't have the name attribute; so its not behaving properly.
I suggest if you want to create radio buttons dynamically either go by Eric's suggestion: