Aakash Goel
Aakash Goel

Reputation: 1179

jQuery live not updating button value on success

okay, here's the situation:

<div>
<a href=".." id=".."></a> //similarly multiple links
</div>

when user clicks on any link, it's id is passed as a GET variable by an AJAX request. Upon success, another <div> gets filled up with a list of buttons that have some values written on them. When the user clicks on the buttons, he can change the value written on the button by typing the new value in the alert box. This too is being done by an AJAX request. Upon success however, the values are updated in the database but the changed value is not written back to the button.

$('#tags a').click(function(e){
e.preventDefault();
var send = $(this).attr('href');
$.ajax({
    url:'getitemsfortag.php',
    data:{tag:send},
    type:'GET',
    dataType:'html',
    success:function(data){
        $('#items').empty().append(data); //data contains list of buttons
    },
    error:function(xhr, status){
        alert("Problem");
    }
});

});

$("input[type='button']").live('click',function(){
var selected = $(this).attr("id");
var val = prompt("Enter new value",0);
$this = $(this);
$.ajax({
    url:'updateCostItems.php',
    data:{toupdate:selected, updatewith:val},
    type:'GET',
    dataType:'json',
    success:function(json){
        $this.val(json.update);
    },
    error:function(xhr, status){
        alert("Problem");
    }
    });
});
});

Any suggestion on how to get the changed value to be written back to the button?

Upvotes: 0

Views: 604

Answers (1)

Matthew Nessworthy
Matthew Nessworthy

Reputation: 1428

$this.html(json.update);

instead of

$(this).val(json.update);

Upvotes: 1

Related Questions