Note that there are some explanatory texts on larger screens.

plurals
  1. POUse AJAX to update records in database
    primarykey
    data
    text
    <p>I have a shopping cart website where the user can add items to his cart. For each item, I have a drop-down list where the user can update the number of items. This is the loop where I show the drop-down list, and marks selected the quantity the user has added to his cart. (<em>quantity available</em> is for the amount of products, while <em>quantity</em> is for the user amount of that product).</p> <p><strong>cart.php</strong></p> <pre><code>echo '&lt;select name="product' . $prod_row["product_id"] . '"&gt;'; for ($i = 1; $i &lt;= $prod_row["quantity_available"]; $i++) { echo '&lt;option value="' . $i . '"'; if ($i == $cart_row["quantity"]) { echo ' selected="selected"'; } echo '&gt;' . $i . '&lt;/option&gt;'; } echo '&lt;/select&gt;'; </code></pre> <p>On the drop-down list <code>onchange</code> I wish to make an AJAX call to update the quantity. I have this Javascript method which I took from <a href="http://www.w3schools.com/php/php_ajax_database.asp" rel="nofollow">W3Schools</a>.</p> <pre><code>function updateCartQuantity(qty, cartid) { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { } } xmlhttp.open("GET","updatecart.php?qty="+qty+"&amp;cartid="+cartid,true); xmlhttp.send(); } &lt;/script&gt; </code></pre> <p>How can I modify this Javascript method to cater for the update of a record?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload