Here is what I am trying to do. I have a simple piece of java script code which takes the value of a checkbox and deletes the corresponding from the database.. Say that I have three options red, blue, yellow displayed and red is selected, the record for red will be deleted.
This code does it perfectly.
var n = $('input[type=checkbox]:checked').val();
db.transaction(function (tx) {
tx.executeSql('delete from details where name = ?',[n],function(){
alert('The event is successfully deleted');
});
});
But the requirement is to capture multiple checkbox selections as well (i.e) if both red and blue are selected or all the three are selected, the code must deleted the records of the selected values. I am able to capture the values selected in an array with the following piece of code.
var checkboxValues = $('.myCheckbox:checked').map(function() {
return $(this).val();
}).get();
Now i need to use this array of strings in a SQL statement. I tried the following piece of code but of no use.
db.transaction(function (tx) {
tx.executeSql('delete from details where name in (?)',[checkboxValues],function(){
alert('The event is successfully deleted');
});
A few other answers suggested me to convert the array object into a comma-seperated string using toString() and join() function but those did not quite help me. I doubt whether my SQL statement is correct. Pls someone help me. Thanks in advance !!