Getting value of html id tag in views?

Ok first off you want to change: <a href="{% url 'login' %}" name="tick_complete" id="{{tasks1.title}}">complete</a>

To: <a href="#" name="tick_complete" id="{{tasks1.title}}" class="complete_link">complete</a>

As a said before, the href attribute will cause the browser to render a new page and stop all javascript, using "#" in the href won't

I also added a class to the anchor tag to make the jquery easier

the jquery is going to look something like this (note all the code in the post is untested, but it should get you close) See references here: http://api.jquery.com/click/ http://api.jquery.com/jquery.post/ https://realpython.com/blog/python/django-and-ajax-form-submissions-more-practice/

$('.complete_link').click(function() {
    var task_title = $(this).attr('id');
    var url = '????'; //THIS NEEDS TO BE THE URL TO YOUR VIEW
    var data = {'task_title': task_title};
    var success = function () {
        console.log('yay');
    };
    $.ajax({
         type: "POST",
         url: url,
         data: data,
         success: success
    });

});

Then your django view would look something like this: def update_task(request): if request.method == "POST": task_title = QueryDict(request.body).get('task_title') Items.objects.get(title=task_title).update(completed=True)

Another thing to consider is you should almost certainly be using the task id or primary key NOT the title So really everything should look like this:

<a href="#" name="tick_complete" id="{{tasks1.id}}" class="complete_link">complete</a>

$('.complete_link').click(function() { var task_id = $(this).attr('id'); var url = '????'; //THIS NEEDS TO BE THE URL TO YOUR VIEW var data = {'task_id': task_id}; var success = function () { console.log('yay'); }; $.ajax({ type: "POST", url: url, data: data, success: success });

});

def update_task(request):
    if request.method == "POST":
        task_id = QueryDict(request.body).get('task_id')
        Items.objects.get(pk=task_id).update(completed=True)
/r/django Thread