Reputation: 851
I am rendering a table row by row from the result array retried from ajax post, and each row have column calls menu I rendered it by function getActionMenu
where the parent is a <td>
and in this menu
column.
I dynamically create one input text box <input type="number" class="input-mini maxStuNum">
and a button <button class="btn btn-primary" type="button">SUBMIT</button>
. When I hit the button, I am serach from self up to its parent then find the input by classname .maxStuNum
to try to get its value and do further.
However, Chrome always says maxStuNum
is Undefined.
From debug console I do see seems the input class="maxStuNum"
is already found. But I don't know what's the meaning of input: jQuery.fn.jQuery.init[1]
Debug:
input: jQuery.fn.jQuery.init[1]
0: input.input-mini maxStuNum
function doSubmit(event){
var tutor = event.data.row;
var input = $(this).parent().children(".maxStuNum");
var maxStuNum = input.attr('value');
}
function getActionMenu(row, parent){
var div = $('<div class="input-append">');
var input = $('<input type="number" class="input-mini maxStuNum">');
input.attr('value',row.maxStuNum);
var btn =$('<button class="btn btn-primary" type="button">SUBMIT</button>').unbind().bind('click', {'row':row}, doSubmit);;
div.append(input);
div.append(btn);
parent.append(div);
}
Upvotes: 0
Views: 84
Reputation: 5615
Your code is fine except this line
var maxStuNum =input.attr('value');
use
var maxStuNum = input.val();
Upvotes: 2