mercredi 11 octobre 2017

Jquery helper function with checkbox foreach

I have a few checkboxes that I am trying to get the values from using a jquery helper function.

<div class="checkbox">
<label>
<input name="gift_wrap" value="Wrap" type="checkbox"> Gift wrap
</label>
<label>
<input name="gift_wrap" value="Wrapper" type="checkbox"> Wrapper
</label>
<label>
<input name="gift_wrap" value="Pap" type="checkbox"> Pap
</label>
</div>

Here's the Jquery:

_getContent: function (elm) {
        if(elm.is(":checkbox, :radio")){
            return elm.is(":checked") ? elm.map(function(){
            return $(this).val()}) : '';
        } else {
            return elm.text();
        }
        return '';
    }

I am getting this [object Object] instead of the values. I am not so good at Jquery and not entirely sure how to go about it, I have also tried .each without much success.




Aucun commentaire:

Enregistrer un commentaire