vendredi 6 mai 2016

Create unique checkboxes dynamically

I want to create checkboxes from a "input type number". This is how far ive come:

Fiddle: My current CODE

html

 <div id="positions">
        <input type="number" class="txt" value="1" style="width: 30px"/>
        <button type="button" class="btnPos">Add pos</button>
    </div>

script

$(document).ready(function () {
    $(".btnPos").on('click', function () {

        $('#positions').append('<input type="checkbox" name="myCheckbox" />' + "Pos " + $(".txt").val());
    });
});

Now I create checkboxes like this: [] pos 1 etc. But I want to create like 7 at the same time. Lets say I choose the number "3" in the input. I want it to create 3 boxes like this: [ ] pos 1 , [ ] pos 2 , [ ] pos 3.




Aucun commentaire:

Enregistrer un commentaire