How can I update my cart with Ajax?
===

I'm looking to build an AJAX script that will update my cart automatically and instantly :

So basically I have this field in php:

    <?php 
    	$options = array(
    		  '0'  => '0',
    		  '1'  => '1',
    		  '2'  => '2',
    		  '3'  => '3',
    		  '4'  => '4',
    		  '5'  => '5',
    		  '6'  => '6',
    		  '7'  => '7',
    		);
    		
    		if($product['quantity']==0){
    			$value[$product['title']] = set_value('quantity'.$product['title']);
    		}else{
    			$value[$product['title']] = $product['quantity'];
    		}
    			echo 	form_dropdown('quantity'.$product['title'], $options, $value[$product['title']]);
    ?>


And I would like to reload my form and update ONLY the necessary fields, is that possible ? Here are the informations I would like it to be updated:

												<td>
													<?php echo $product['price'] ?>
												</td>
												<td>
													$<?php echo $total[$product['title']] ?>
												</td>
											</tr>
											<?php
												}
											?>
											<tr class="alt">
												<td colspan='4' style="text-align:right;" id="bottom-left">
													<strong>Price Before Reduction and without taxes and without shipping<strong>
												</td>
												<td style="text-align:center;" id="bottom-right">
													<strong><?php echo '$ '.$totalPrice; ?></strong>
												</td>
											</tr>
											<?php if(ISSET($ReducP) AND $ReducP != 0){ ?>
											<tr class="alt">
												<td  colspan='4' style="text-align:right;"  id="bottom-left">
													<strong>Reduction Amount (<?php echo $ReducP; ?> % off)<strong>
												</td>
												<td style="text-align:center;" id="bottom-right">
													<strong><?php echo '- $'.$Reduc; ?></strong>
												</td>
											</tr>
											<?php } ?>
											<tr class="alt">
												<td colspan='4' style="text-align:right;" id="bottom-left">
													<strong>Shipping<strong>
												</td>
												<td style="text-align:center;" id="bottom-right">
													<strong><?php echo '$ '.$shipping; ?></strong>
												</td>
											</tr>
											<tr class="alt">
												<td colspan='4' style="text-align:right;" id="bottom-left">
													<strong>Total Price WIth Taxes, shipping and reduc<strong>
												</td>
												<td style="text-align:center;" id="bottom-right">
													<strong><?php echo '$ '.$totalPriceWithTaxes; ?></strong>
												</td>

Should I re-write my php function in javascript ? Here is my function that get the price for me:

       function Price($coupon = NULL){
    	
    				
    		// We save the sessions datas into an array
    			$data ['session'] = $this->session->all_userdata();
    			$data ['taxes'] = $this->front_model->getTaxes('United States');
    			$this->session->set_userdata('taxes', $data ['taxes']);
    			
    		// We get every product information where quantity != 0
    			foreach ($data['session']['quantity'] as $color => $product_quantity) {
    				if ($product_quantity != 0){
    
    					// On récupère le  produit
    					$data['products'][$color] = $this->front_model->getProduct($color);
    					$data['products'][$color]['quantity'] = $product_quantity;
    					
    				};
    			};
    			$this->session->set_userdata('products', $data ['products']);
    		//for each product we get the price and the total price for this product (*quantity) that gives the price without taxes.
    		// Set some var to 0
    		$totalQty = 0;
    		$data['totalPrice'] = 0;
    		
    		foreach ($data['products'] as $product) {
    			
    			$data['total'][$product['title']] = $product['quantity']*$product['price'];
    			$data['totalPrice'] += $data['total'][$product['title']];
    			$totalQty ++;
    		};
    		$this->session->set_userdata('total', $data['total']);
    		$this->session->set_userdata('totalPrice', $data ['totalPrice']);
    		
    		// Reduction calul process.
    		if(	$this->session->userdata('Token')=='TRUE' OR $this->session->userdata('Token')=='FALSE' AND $coupon != NULL){
    			$data['ReducP'] = $this->front_model->getReduc('Repetitas');
    			$data['ReducP'] = $data['ReducP']->reduction;
    			$data['Reduc'] = ($data['totalPrice'] * $data['ReducP'])/100;
    			$data['totalPriceWithReduc']= $data['totalPrice'] - $data['Reduc'];
    			$data['totalPrice'] = $data['totalPriceWithReduc'];
    			
    			$this->session->set_userdata('ReducP', $data['ReducP']);
    			$this->session->set_userdata('Reduc', $data ['Reduc']);
    			$this->session->set_userdata('totalPriceWithReduc', $data ['totalPriceWithReduc']);
    		
    		};
    		
    		//Taxes calcul
    		$data['tax'] = $data['totalPrice']*$data ['taxes'];
    		$this->session->set_userdata('tax', $data ['tax']);
    
    		//That we save in session
    		$this->session->set_userdata('tax', $data['tax']);
    
    		//Get the shipping amount
    		$data['Shipping'] = $this->front_model->getShipping('United States');
    		$this->session->set_userdata('shipping', $data ['Shipping']->shipping);
    		
    		//We calcul the final price with taxes, shipping and everything.
    		$data['totalPriceWithTaxes'] = $data['tax'] + $data['totalPrice'] + $data['Shipping']->shipping;
    		$this->session->set_userdata('totalPriceWithTaxes', $data ['totalPriceWithTaxes']);
    		
    		return True;
    	}

The thing is if I should do it in javascript, I have no clue about how to adapt it. So is there a way to keep my php function as is ? how could I get my variables back ?

thank you !