JavaScript - Unable to get names of selected checkboxes -
i have made javascript code see checkboxes checked.
<script> var savetestvalue = function() { var selected = []; $('#checkboxes input:checked').each(function() { selected.push($(this).attr('name')); }); alert(selected); }; </script> <form> <input type="checkbox" name="a" value="a"> <input type="checkbox" name="a" value="b"> b <input type="submit" value="save" onsubmit="savetestvalue()"> </form>
browser making no alert on calling script.
onsubmit="savetestvalue()"
should in form
element, not input
element
<form onsubmit="savetestvalue()"> .... </form>
but can define onclick
event input
element if want.
javascript
No comments:
Post a Comment