views:

113

answers:

2

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.

+7  A: 

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.

Alex
+2  A: 

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.');
  }
});
Jeff V
wow... JS Framework for someone who has trouble with basic javascript. A little extreme, in my opinion.
Alex
@Alex - You are probably right... But he was looking for a way to do it, and I gave him a way... :)
Jeff V