How to select value of html radio button list using Javascript ?


radio1
Hi
One of my friend, asked with me, how to select the value of html radio button list using Javascript ?

In html radio button list, we can select the value like this


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/jscript">
        function getResults() {
            var radios = document.getElementsByName("group1");

            for (var i = 0; i < radios.length; i++) {
                if (radios[i].checked) {
                    alert(radios[i].value);
                    break;
                }
                        }

//            if (radios[0].checked) {
//                alert('Male');
//            }
//            else {
//                alert('Female');
//            }

           
        }
    
    </script>
</head>
<body>
<input type="radio" value="Male" id="radio1" name="group1" /> Male  
<input type="radio" value="Female" id="radio2" name="group1" /> Female <br />
<br />
<input type="button" id="btnClik" value="Click Here" onclick="getResults();" />
</body>
</html>


Advertisements

2 Responses to “How to select value of html radio button list using Javascript ?”

  1. http://comunidad.molinux.info Says:

    Good blog! I truly love how it is simple to read. I’m curious how I could be notified whenever a new article has been created. I’ve subscribed to your RSS which
    should do! Have a great day and please excuse my bad english!

    • Chandra Dev Says:

      You are welcome. Thanks for posting your kind and soft feedback. You can follow my blog. if i will post any artical then you will get the email.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: