My response got swallowed by the system.
Usually when the system does not respond I can just backup to the screen I entered the message on and wait to hit submit again but this time it wiped it out. *Sigh*
Anyway, as kaht has already pointed out the onclick event fires AFTER you have changed the state of the radio box so of course it will always show that it was checked because you just checked it.
You need to test what the state was prior to the onclick which is what kaht's example above shows using the onmousedown event. The only problem with this is that if the users tabs to the field and hits the spacebar in order to select the field then the onmousedown is not going to fire.
My solution was this:
First, set a global variable on the page to store the state of that button in.
Then use something like this in your HTML
Code:
<input type="radio" name="R1" value="T" onfocus="R1State = this.checked;" onclick="if (R1State) {alert('Already Checked');} else {alert('Newly Checked')};">
<input type="radio" name="R1" value="R">
I use the onfocus event to test the current state of the radio button and store it in the global variable R1State.
Then I use the onclick event to test the value of R1State rather than testing the radio button directly because if you just clicked on the radio button you KNOW it will be checked.
I do not know if this will be cross-browser friendly, sometimes the methods for handling events or the order they occur in vary between browsers but it works in IE6.
To make it more robust you would have a separate function and in that function you would keep track of the state of whatever radio buttons you needed to check. You would call that function from the onclick event rather than from onfocus.
At my age I still learn something new every day, but I forget two others.