I could use a little help. I've loaded the objects in an array that I've made in PHP into a bunch of input boxes. The objects are for a shopping cart: price, quantity, and total price respectively. While the data loads up fine, it seems to be read-only.
For example, the input text value for quantity says 1, and I can't change it.
I want to be able change the quantity without having to go back to my MySQL table.
I can do it just fine with regular Ajax, but when I use regular Ajax, the item won't load without refreshing like all of my other ajax functions.
Here's the code.
function updates(){
$.getJSON("classes/cartlist.php", function(data) {
$("#cart_list, #cart_table").empty();
$.each(data.result, function(){ $("#cart_list, #cart_table").append(
"<tr id='"+this['id']+"'>
<td> "+this['pro_title']+" </td>
<td> <input type='text' id='price-"+this["p_id"]+
"' class='price' pid='"+this["p_id"]+
"'value='"+this["price"]+"' />
</td>
</tr> ");
});
});
This isn't everything but the two other input boxes are just the same thing. I figured this'd be easier to read if I left it like this.
EDIT: Here's what the quantity input text box looks like, since someone asked.
<td><input type='text' id='qty-"+this["p_id"]+"' class='qty' pid='"+this["p_id"]+"' value='"+this["qty"]+"' />
EDIT: Okay so I've found the reason I can't change the text and that is the set interval function that is going with the JSON
function done() {
setTimeOut (
function(){
updates();
}, 300)
}
But if I get rid of that I'll have to refresh the page to get my data back..
i think there is an error in append string to
function updates(){
$.getJSON("classes/cartlist.php", function(data) {
$("#cart_list, #cart_table").empty();
//make use of index and value inside function
$.each(data.result, function(index,value){
// here some thing with your code because
indicate the end of statement so
$("#cart_list, #cart_table").append(
"<tr id='"+this['id']+"'>" +
"<td> "+this['pro_title']+" </td> "+
"<td> <input type='text' id='price-"+this["p_id"]+
"' class='price' pid='"+this["p_id"]+
"' value='"+this["price"]+"' />"+
"</td>"+
"</tr> ");
});
});