<body> <input type="checkbox" name="BE" value="BE">BE <input type="checkbox" name="ME" value="ME">ME <input type="checkbox" name="MS" value="MS">MS <input type="checkbox" name="MCA" value="MCA">MCA <button id="myButton">Click</button> <button onclick="location.reload();">Reset</button><br> <span id="checkedSpan"></span> </body>
$(document).ready(function() { $("#myButton").click(function() { var text = ""; $(":Checked").each(function() { text =text + " "+ $(this).val(); }); var spanText = $("#checkedSpan").html(); if(spanText != null) { $("#checkedSpan").innerHTML = " "; } $("#checkedSpan").html("You selected: "+text); }); });