0

I have multiple, and I want to get the value, the attributes of each selected checkboxes.

<input type="checkbox" name="access[]" id="configuration" value="configuration" data-text="Configuration"> Configuration
<input type="checkbox" name="access[]" id="department" value="department" data-text="Departments"> Departments 

I want to get all selected checkbox and store it to an array and push it to ajax

var classids = checkboxes.map(function(){ return $(this).attr("id"); }).get();
var val      = checkboxes.map(function(){ return $(this).val(); }).get();
var datatext = checkboxes.map(function(){ return $(this).attr("data-text"); }).get();

How can I combine the three to make it one? Thanks in advance

1 Answer 1

1

To get an array of object, you could just map relevant properties you are looking for:

var arr = checkboxes.filter(':checked').map(function(){
  return {classids : this.id, val: this.value, datatext: this.dataset['text']}
}).get();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.