I'm building a simple table from an array with an edit button for each table row. The value passed to the php page on submit via POST needs to be associated with the qnumber for the line. Everything works except I can't assign the "value" attribute to a variable. The code works correctly if I hard code the value attribute for the button. As you can see below, I've tried to modify via attr but this is not working despite verification that qnumber is returning a valid value.
How can I assign the value property of each line's edit button via a variable?
var $tablebody = $('<tbody</tbody>');
for (var i = 0; i <result.length - 1; i++) {
var quest = result[i];
var qnumber = quest.qnumber;
var $row = $('<tr></tr>');
$row.append($('<td></td>').text(quest.question));
$row.append($('<td></td>').text(quest.a1));
$row.append($('<td> <button name="subject" id="subject" type="submit" formaction = "test1.php" value="">Edit</button> </td>'));
$('#subject').attr('value', qnumber);
$tablebody.append($row);
}