I want to show my checkbox value when I check it, but my code show only one value.
For example if I check 1st checkbox it show it's value at that time. If I check 2nd checkbox then it's value will display beside previous value.
What should I do?
<script> function test(item) { var result = $('#val').val(); $('#course').html(result); } </script> <html> <div id="show"> <span id="course"> </span> </div> <input type="checkbox" id="val" value="20" onclick="test()" />20 <br /> <input type="checkbox" id="val" value="30" onclick="test()" />30 <br /> <input type="checkbox" id="val" value="40" onclick="test()" />40 <br /> </html>
$('#course').html(result);to$('#course').append(result);also youthiscontext and to get current checkbox.