0

Is there a way so i can set a html checkbox with a bidimensional array, something like this:

<input type=checkbox name=message[group1][1] value=1>

If yes,

1) how should I do to accomplish that in case the example I wrote is wrong?

2) how could I access those elements from a request handler in django?

1 Answer 1

1

Yes, you can use such checkboxes names, ultimately it's just a string. To get all elements on server side you could generate checkboxes names and get its values. Like this:

def multi(request):
    arr = []
    for x in range(1, 6):
        cur_row = []
        arr.append(cur_row)

        for y in range(1, 6):
            curr_cell = bool(request.POST.get('message[group%d][%d]' % (x, y)))
            row.append(curr_cell)

    return HttpResponse('ok')

But server needs to know what ranges will come to process all checkboxes. I set 1..5 range for example.

PS. Is value attribute as valid for checkboxes? What about checked attribute?

Sign up to request clarification or add additional context in comments.

1 Comment

thanks demalexx! i'll try to implement your suggestions and let you know how it turns out! The value attribute was just for a sake of example.

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.