How to check which radio button has been selected in javascript?
If (acctR开发者_JAVA技巧B.Checked == true)
{
Execute Business Code
}
Well, you don't need the == true
:
if (acctRB.checked)
{
// It's checked
}
else
{
// It's not checked
}
So what you have is pretty much correct. Just remove the == true
as it's not required.
Bear in mind that IE is case insensitive while other browsers aren't. Your sample code will work for IE....
Rather do
if (acctRB.checked) {
//Checked
} else {
//Unchecked
}
It works for both IE and other major browsers....Or, if if checkbox id is "acctRB"
do,
if (document.getElementById("acctRB").checked) {
//Checked
} else {
//Unchecked
}
精彩评论