开发者

How to check which radio button has been selected in javascript?

开发者 https://www.devze.com 2023-01-18 14:41 出处:网络
If (acctR开发者_JAVA技巧B.Checked == true) { Execute Business Code } Well, you don\'t need the == true:
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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消