Mario
Mario

Reputation:

print value of check box

i have 10 check box. I want to capture in array and print value as the user checked checkbox. if he uncheck, value should be unprinted.

Upvotes: 0

Views: 362

Answers (1)

meder omuraliev
meder omuraliev

Reputation: 186692

$('#form').submit(function(e) {
    var errorElements = [], valid = false;

 $('.checkboxgroup', this).each(function() {
        var checkBoxes = $(':checkbox', this), oneChecked = false;
        checkBoxes.each(function() {
            if ( !oneChecked && !$(this).is(':checked') ) {
                valid = false;
                errorElements.push(this);
            } else {
                oneChecked = true;
            }
        });
    });

  e.preventDefault(); // cancels form submit.. remove if you dont need.

  if ( errorElements.length ) {
     // code to do what you want if it fails
  } else {
     // code to do what you want if it passes
  }


});

html:

<div class="checkboxgroup">

( checkbox html )

</div>


<div class="checkboxgroup">

( checkbox html )

</div>

Upvotes: 1

Related Questions