I'm currently working on implementing AJAX functionality in Django with the help of jQuery. The issue I'm facing is that the ID of the element I need to modify is not fixed; it's a Django template variable, so each element in the table has a different ID. Despite this variability, I want to be able to use AJAX to update that specific element. To achieve this, I am passing a dictionary from a Django view to JavaScript using simplejson. The crucial objects within this dictionary are the ID and model (note that these are placeholder names for clarity). Below is some pseudo code (written in a Python-like syntax as I'm unsure how to do it in JavaScript):
var quantity_update = function(msg, elem) {
var response_obj = eval('(' + msg + ')');
var newtotal = document.getElementById("%s, %s"); % (response_obj.id, response_obj.model)
subtotal.innerHTML = "<td>"+response_obj.subtotal+"</td>";
My question is: Is it possible to accomplish something like this in JavaScript, and if so, could someone provide insights on how to do it?