mardi 29 mai 2018

Getting text from a checked checkbox

I have a collection of checkboxes within a bunch of elements:

<label class="control-label">Items</label>
<div class="controls">
    <div id="13" class="checkboxes columns-container columns-count-two">
        <div class="column-item">
            <label class="checkbox">
                <input name="13[]" value="Item 1" type="checkbox">Item 1
            </label>
        </div>
        <div class="column-item">
            <label class="checkbox">
                <input name="13[]" value="Item 2" type="checkbox">Item 2
            </label>
        </div>
        <div class="column-item">
            <label class="checkbox">
                <input name="13[]" value="Item 3" type="checkbox">Item 3
            </label>
        </div>
    </div>
</div>

I'm using the following JavaScript code to try and get the text of the checked item, but it doesn't seem to be working. I'm not sure what I'm missing, some assistance will be greatly appreciated

var checktext = $('#13 input:checkbox:checked').map(function() {
return $(this).next("label").text().split(' ').join('%20');
}).get();




Aucun commentaire:

Enregistrer un commentaire