Hey there
i have a php cart that i have done using class and functions, and when it came to deleting a selected item or all items, i wanted to use JS to do it, is there any way to accomplish it.
Hey there
i have a php cart that i have done using class and functions, and when it came to deleting a selected item or all items, i wanted to use JS to do it, is there any way to accomplish it.
Click here to solve your problem.
It is called, AJAX. You create a request from JavaScript. Requested page/script receives parameters and does things and then returns response.
The answer to this depends on how you are outputting the information in PHP. Assuming that there is some sort of checkbox with a product id (or something) then you should be able to do something like this (you will have to modify):
Loop through your checkboxes or whatever elements you might have:
if($(this).is(":checked")){
myArray[countVar] = $(this).attr("name")
}
Then pass in the array via Ajax to a WebService or .php for saving:
var jsonText = JSON.stringify({param:myArray });
$.ajax({
type: "POST",
data: myArray,
dataType: "json",
url: 'webservice or .php page',
success: function(data) {
$('.result').html(data);
alert('delete was performed.');
}
});