Reputation: 627
Say I want get an element via its name and it's an item in the list. I need to specify what index it is. I'm getting the value for the index from another element:
var testid = $(this).data('testid');
$('[name="TestDtos["' + testid + '"].Save"]').val(this.checked);
So say the testid was 7 I would want it to read:
$('[name="TestDtos[7].Save"]').val(this.checked);
So the value of the index comes through fine. The problem I think is when I try to add the testid value inside the "[]". Does anyone know what I'm doing wrong? I'm not really sure what I'm doing here.
Upvotes: 0
Views: 48
Reputation: 15919
You had extra double quotes. It should be,
var testid = $(this).data('testid');
$('[name="TestDtos[' + testid + '].Save"]').val(this.checked);
Upvotes: 3