i am trying to get array from checked buttons when i clicked a button and i also want to get the value of the clicked button i am able to get the array part but i am unable to get the value of the button
below is my code
$('.multiple').on("click", function () {
var action = $(this).val();
var yourArray = $("input:checkbox[name=type]:checked").map(function () { return $(this).val() }).get()
console.log(action);
var jsonString = JSON.stringify(yourArray);
console.log(jsonString);
$.ajax({
type: "POST",
url: "../sales/script.php",
data: { data: jsonString, action: action },
cache: false,
success: function (response) {
console.log(response);
}
});
});
what i want is to pass the clicked button value so that code can determine what it should do with the data
my button is
<div class="btn btn-success btn-sm multiple" value="delete">Delete</div>
2
Answers
You can use attr for this:
Here is the demo