Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i need the ajax script to pick up the name and value of the textbox being edited, and pass them to update.php i have been searching for weeks now and cannot find an answer, i am new to ajax.




JavaScript
<script type='text/javascript'>

function updateqty(this) { 

   itemname = $(this).attr('name').slice(9, -1);
   itemqty = $(this).value;  


    if (window.XMLHttpRequest) {
        xmlhttp1 = new XMLHttpRequest();
    }
    xmlhttp1.onreadystatechange = function () {
        if (xmlhttp1.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("cart1").innerHTML = xmlhttp1.responseText;
        }
    }
    alert(itemname);
    xmlhttp1.open("GET", "php/updateqty.php?order=238&id=" + itemname + "&qty=" + itemqty, true);
    xmlhttp1.send();
}




</script> 



HTML
<div id="cart1">

   <table id='POITable' width='100%' border='1'>
        <tr>
            <td>SKU</td>
            <td>QTY</td>
            <td width='45%'>item</td>
            <td>Unit Price</td>
            <td>Line Price</td>
            <td>Delete</td>
        </tr><tr><td>99966</td><td>

<input type='text' name='quantity[779]' size='3' value='3' tabindex='1' onblur='updateqty(this)' />

</td><td>Dewalt Work Boots size 9</td><td>24.99</td><td>74.97</td><td><img src='images/btn_delete.png'  önclick='deleteRow(this)' height='30'/></td>
<tr><td>10004</td><td>

<input type='text' name='quantity[778]' size='3' value='1' tabindex='1' onblur='updateqty(this)' />

</td><td>Work Hat</td><td>2.45</td><td>2.45</td><td><img src='images/btn_delete.png'  önclick='deleteRow(this)' height='30'/></td>
<tr><td>10192</td><td>

<input type='text' name='quantity[777]' size='3' value='1' tabindex='1' onblur='updateqty(this)' />

</td><td>Dickies Work Trousers 30/32</td><td>19.99</td><td>19.99</td><td><img src='images/btn_delete.png'  önclick='deleteRow(this)' height='30'/></td>
<tr><td>10101</td><td>

<input type='text' name='quantity[776]' size='3' value='1' tabindex='1' onblur='updateqty(this)' />

</td><td>Garden Tap Kit</td><td>9.99</td><td>9.99</td><td><img src='images/btn_delete.png'  önclick='deleteRow(this)' height='30'/></td>
</div>



Any help on this matter would be greatly appreciated

Thanks in advance
Posted
Updated 15-May-13 0:50am
v3

change all this to something else
JavaScript
function updateqty(element) { 
 
   itemname = $(element).attr('name').slice(9, -1);//you can simply write element.name.-----
   itemqty = $(element).val();//value is changed. 

//you are using jquery. so simple would be 
$.ajax({
url: "your_link.php",
type: 'GET', 
dataType: 'html', 
data: "data=value&data2=value2", 
timeout: 90000, 
success: function(html)
 { 
   //whatever you want to do with your return data. 
 });
}
 
Share this answer
 
Below is the JQuery sample code for making Ajax call. One more thing, I think you can use onChange event instead OnBlur.
JavaScript
$.ajax({
        type: "GET",
        url: "php/updateqty.php",
        data: "order=238&id=" + itemname + "&qty=" + itemqty,
        success: function(msg) {
            //Right Code if you want to process response  from server
            
        }
    })
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900