Click here to Skip to main content
15,901,982 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how is it possible with javascript to increment counter if correct radio button is clicked

What I have tried:

used javascript to display the value of selected radio button would want the counter to increment if correct button is clicked
Posted
Updated 28-Dec-17 3:13am
v3
Comments
[no name] 28-Dec-17 8:56am    
Google can provide you the samples of code...

1 solution

try this, solution based on your previous question

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>C S</title>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script type="text/javascript">

        var counter = 0;
        $(document).ready(function () {
            $('#btnGetValue').click(function () {
                var selValue = $('input[name=rbnNumber]:checked').val();
                counter += parseInt( selValue);
                $('p').html('<br/>Counter: ' + counter + '');
            });
        });
    </script>
</head>
<body>
    <input type="radio" name="rbnNumber" value="1" /> Number 1<br />
    <input type="radio" name="rbnNumber" value="2" /> Number 2 <br />
    <input type="radio" name="rbnNumber" value="3" /> Number 3 <br />
    <input type="radio" name="rbnNumber" value="4" /> Number 4 <br />
    <input type="radio" name="rbnNumber" value="5" /> Number 5
    <br /><br />
    <input type="button" id="btnGetValue" value="Increament Counter" />
     <p style="font-size:25px;">0</p>
</body>
</html>
 
Share this answer
 
Comments
four systems 28-Dec-17 9:21am    
thanks could think on those lines
Karthik_Mahalingam 28-Dec-17 23:28pm    
cool

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900