user2694709
user2694709

Reputation: 21

how to process checked checkbox with array name?(jquery)

i have a checkbox array name "skills[]" and i want add a text to side of clicked(checked) checkbox(whithout Submit) my code like this:

<li><input name="skills[]" class="skills" value="1" type="checkbox" /></li>
<li><input name="skills[]" class="skills" value="2" type="checkbox" /></li>

wutdo? Thanks,

Upvotes: 1

Views: 65

Answers (2)

Martin Lantzsch
Martin Lantzsch

Reputation: 1901

$('input.skills').on('change', function() {
    if($(this).is(':checked'))
    {
        $(this).parents('li').append('<span class="text">your text</span>');
    } else {
        $(this).parents('li').find('.text').remove();   
    }
});

Working jsfiddle: http://jsfiddle.net/V3TZn/4/

Upvotes: 1

Somnath Kharat
Somnath Kharat

Reputation: 3600

Try this: DEMO

 $("input[name='skills[]']").change(function(){
    if($(this).is(':checked')){
       $(this).parents('li').append('<span class="text">your text</span>');
    } 
    else {
    $(this).parents('li').find('.text').remove();   
    }
});

Upvotes: 0

Related Questions