0

I have a ajax script which takes a field from my django form and retrieves a price field - Working Fine

I have a paypal form which I need to update the "amount" value with this retrieved value price. But when I pass it in it is returning as an object.

Would really appreciate any help or better way to accomplish this.

HTML:

<h1>Pay using PayPal</h1><form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="amount" value="0" id="id_amount">
</form>

<script>
$("#id_membership_title").change(function () {
  var url = $("#regForm").attr("data-member-url"); 
  var membership_title = $(this).val(); 

  $.ajax({                      
    url: url,                   
    data: {
      'membership_title': membership_title     
    },
    success: function (data) {
      $("#id_amount").html(data);
      $("#id_price").html(data);
    }
  });
      price = document.getElementById("id_amount");
      price.setAttribute("value", $("id_amount"));
});

View To Retrieve Price:

def ajax_load_price(request):
    membership = request.GET.get('membership_title')
    mem_id = ClubMemberships.objects.filter(pk=membership)
    return render(request, 'load_price_value.html', {'mem_id': mem_id})

HTML to render price:

{% for id in mem_id %}
   {{ id.price }}
{% endfor %}
GavB841
  • 23
  • 2
  • Possible duplicate of [Where's my JSON data in my incoming Django request?](https://stackoverflow.com/questions/1208067/wheres-my-json-data-in-my-incoming-django-request) – Smart Manoj May 26 '19 at 14:15

1 Answers1

0

try updating this line: $("#id_amount").html(data);

to instead: $("#id_amount").val(data);

Scott Flodin
  • 320
  • 1
  • 5