1

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;*/
    }
  });

})
4
  • document.getElementById("total_products").value(response); Commented May 24, 2016 at 14:29
  • 2
    $('#total_products').attr('value',response) Commented May 24, 2016 at 14:32
  • thanks man it works. Commented May 24, 2016 at 14:38
  • $('#total_products').val(response); Commented May 24, 2016 at 14:40

2 Answers 2

6

Although the above solution is right, the normal way to do this in jQuery is :


$('#total_products').val(response);
Sign up to request clarification or add additional context in comments.

Comments

2

Use this:

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

jQuery attr documentation:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.