Search code examples
jqueryajaxjquery-selectors

ajax response in input value attribute


Commented response works properly, but I want to do something like $('#total_products').attr('value') = response; but this is not working. Why is this not working, and how can I resolve it?

$(document).ready(function(){

  $.ajax({
    type : 'post',
    url : 'product_store.php',
    data : {
      total_products: "totalproducts"
    },
    success:function(response) {
      $('#total_products').attr('value') = response;
      /*document.getElementById("total_products").value=response;*/
    }
  });

})

Solution

  • Use this:

    $('#total_products').attr('value',response);
    

    jQuery attr documentation:

    http://api.jquery.com/attr/