In This Javascript Tutorial we will see How To Get The Selected RadioButton Value Array In JS Using Netbeans Editor .

Subscribe : https://www.youtube.com/channel/UCS3W5vFugqi6QcsoAIHcMpw

Project Source Code:

<!DOCTYPE html>

<html>
    <head>
        <title>JavaScript Radio Button</title>
        <meta charset="UTF-8">
        
        <script>
            
            // by name
                function func() 
                {
                    var type = document.getElementsByName("type");
                    if(type[0].checked)
                    {
                        var val = type[0].value;
                        alert(val);
                    }
                    
                    else if(type[1].checked)
                    {
                        var val = type[1].value;
                        alert(val);
                    }
                    
                    else if(type[2].checked)
                    {
                        var val = type[2].value;
                        alert(val);
                    }
                }
                
                // by Id
                 function func2() 
                {
                    if(document.getElementById("h").checked)
                    {
                        var val = document.getElementById("h").value;
                        alert(val);
                    }
                    
                    else if(document.getElementById("r").checked)
                    {
                        var val = document.getElementById("r").value;
                        alert(val);
                    }
                    
                    else if(document.getElementById("a").checked)
                    {
                        var val = document.getElementById("a").value;
                        alert(val);
                    }
                }
    
        </script>
        
    </head>
    <body>
        
<input type="radio" name="type" value="1111" id="h" onclick="func2();"/>0 Human<br/>
<input type="radio" name="type" value="2222" id="r"  onclick="func2();"/>1 Robot<br/>
<input type="radio" name="type" value="3333" id="a" onclick="func2();"/>2 Animal<br/>
        
    </body>
</html>

#js #javascript

How To Get The Selected Radio Button Value Using Javascript  [ with source code ]
3.15 GEEK