JSFiddle - React, Tailwind, and code Playground

by Alex Azuero

HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Get Values of Selected Checboxes</title>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("button").click(function(){
            var favorite=0;
            $.each($("input[name='sport']:checked"), function(){            
                //alert($(this).val());
                favorite+= + this.value
                return favorite
                
                //favorite.push($(this).val());
            });
          alert (favorite)
        });
    });
</script>
</head>
<body>
    <form>
        <h3>Select your favorite sports:</h3>
        <label><input type="checkbox" value="1" name="sport"> Football</label>
        <label><input type="checkbox" value="2" name="sport"> Baseball</label>
        <label><input type="checkbox" value="3" name="sport"> Cricket</label>
        <label><input type="checkbox" value="4" name="sport"> Boxing</label>
        <label><input type="checkbox" value="5" name="sport"> Racing</label>
        <label><input type="checkbox" value="6" name="sport"> Swimming</label>
        <br>
        <button type="button">Get Values</button>
    </form>
</body>
</html>