JavaScript Get multiple values out of checkboxes [duplicate] multiple values checkboxes,multiple checkbox values in php,multiple values

This question already has an answer here:
Answer:1

hier is an example may help you

$(':checkbox').change(function(){
    var liste2 = $(':checkbox:checked').map(function() {
    return this.value;
}).get();
   $('span').text('the checked values are: ' + liste2);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
   <input type="checkbox" name="options[]" value="1" />
   <input type="checkbox" name="options[]" value="2" />
</div>
<div>
   <input type="checkbox" name="options[]" value="3" />
   <input type="checkbox" name="options[]" value="4" />
   <input type="checkbox" name="options[]" value="5" />
</div>
<span></span>
Answer:2

There is simply a typo in your code: this:

 return +e.value;

must be

 return e.value;

The prefix + is only defined for numbers, so javascript tries to convert the "Teamsport" into a number - which is NaN (not a number)

Answer:3

The problem lies here: return +e.value;

+e.value will return NaN for non-number values, in this case, String will be converted to NaN

function calculate() {
  var arr = $.map($('input:checkbox:checked'), function(e, i) {
    return e.value; // +e.value will return NaN for String and non number values
  });
  $('span').text('the checked values are: ' + arr.join(','));
}

calculate();
$('div').delegate('input:checkbox', 'click', calculate);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
  <input type="checkbox" name="options[]" value="abc" />
  <input type="checkbox" name="options[]" value="pqr" />
</div>
<div>
  <input type="checkbox" name="options[]" value="xyz" />
  <input type="checkbox" name="options[]" value="lmn" />
  <input type="checkbox" name="options[]" value="ccc" />
</div>
<span></span>
Answer:4

Just return the e.value in your map function.

function calculate() {
  var arr = $.map($('input[type="checkbox"]:checked'), function(e, i) {
    return e.value;
  });
  $('span').text('the checked values are: ' + arr.join(','));
  // console.log('the checked values are: ' + arr.join(','))
}

calculate();
$('div').on('click', 'input:checkbox', calculate);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div>
  <input type="checkbox" name="options[]" value="Teamsport" />
  <input type="checkbox" name="options[]" value="Individual sport" />
</div>

<span></span>
Answer:5

I've got this object variable: var Background = { x: 0, y: 0, speed: 4, initialize: function (x, y){ this.x = x; this.y = y; move: ...

I've got this object variable: var Background = { x: 0, y: 0, speed: 4, initialize: function (x, y){ this.x = x; this.y = y; move: ...

  1. object variables array javascript
  2. object array variable
  3. ssis object variable array
  4. object variable inside array
  5. php object array variable
  6. powershell variable object array
  7. static variable object array
  8. javascript declare object array variable
  9. ssis object variable string array

i am getting the data like this October 17, 2017 at 5:47:37 PM UTC+5:30 Now, how can i convert it to timestamp like 55773**998 ?

i am getting the data like this October 17, 2017 at 5:47:37 PM UTC+5:30 Now, how can i convert it to timestamp like 55773**998 ?

  1. firestore create timestamp
  2. firestore.timestamp
  3. firestore timestamp now
  4. firestore timestamp
  5. firestore add timestamp

I have a div (top navigation) that is nested inside a flex container. When the top-nav expands, I want it to occupy the full height of the viewport. I know this can be achieved by setting a height of ...

I have a div (top navigation) that is nested inside a flex container. When the top-nav expands, I want it to occupy the full height of the viewport. I know this can be achieved by setting a height of ...

I am having a premium channel on vimeo. I am trying to put a list of videos and their duration on my website. They have an example by using the event listeners. But as I am interested in simple text ...

I am having a premium channel on vimeo. I am trying to put a list of videos and their duration on my website. They have an example by using the event listeners. But as I am interested in simple text ...

  1. video duration using ffmpeg
  2. get video duration using jquery
  3. get video duration using ffmpeg
  4. get video duration using php
  5. get video duration using javascript
  6. get video duration using python
  7. duration using video