Javascript code/ function to validate Radio Button | Check Radio button is checked

By
Advertisement
Introduction:
In my previous article I have explained about Code used to validate emailid using javascript. In this article I am going to explain about How to remove html tags from the input string
Explanation:
For explanation purpose I have two radio buttons with name “gender”. While clicking on the validate button I am checking whether any one gender is selected.
Below is the javascript code used to validate the radio button.
function fnCheckRadio(name) {
    var flag = "0";
    var objs = document.getElementsByName(name);
    if (objs) {
        if (objs.length > 0) {
            for (var i = 0; i < objs.length; i++) {
                if (objs[i].checked == true) {
                    alert("Selected Value is " + objs[i].value);
                    return;
                }
            }
            if (flag == "0") {
                alert("Radio button is not checked..");
            }
        }
    }
}

Here is the demo..
--------------------------
Male
Female

 
--------------------

Do you like this article? Help us to improve. Please post your comments below.

0 comments:

Post a Comment

Online Casino