[Fixed]-AJAX/Django – where to put object id in HTML button?

1👍

You can use a data attribute which lets you store information on an element.

<button name="delete-button" id="" data-id={{record.id}} type="button">Delete order</button>

You can then pull the value from the data attribute in your click handler.

function onClick (event) { var id = event.target.dataset.id; }

0👍

You could use:

delete = tables.TemplateColumn('<button name="delete-button" 
id="delete-button-{{record.id}}" value={{record.id}} type="button">Delete order</button>')

That way each button will have it’s own id ej: delete-button-1 and will have a reference to the id of the record.

Leave a comment