I am trying to assign the value of my rows of my datatable to an input, but I have the following situation, when giving a console.log to the variable that gives me the desired value, it correctly shows me this value, but when assigning that value to my input, I receive thisk.fn.init(1)
I leave below the console.log of the desired value (n_class) and what my input (class) receives
Code
var dt = $("#horarioPracticoEditar_dt").DataTable();
var n_clase = parseFloat(dt.rows().count()) + 1;
var clase = $('#numero_clase').val(n_clase);
console.log(
[
n_clase,
clase
]);
console.log
(2) [3, k.fn.init(1)]
0: 3
1: k.fn.init [input#numero_clase]
length: 2
__proto__: Array(0)
by the way, i also tried this way and got the same result
var clase = $('#numero_clase').val(parseFloat(dt.rows().count()) + 1);
Problem:
The main problem is the misconception that it returns
$('#numero_clase').val(n_clase);
.$('#numero_clase').val(n_clase);
returns the modified object for later useAND
objeto.val()
correctly returns thevalue
current oneSolution:
Instead of using the output of
$('#numero_clase').val(n_clase);
using$('#numero_clase').val();
no parameters so that it correctly returns thevalue
.In this way, that part of the code would look like this:
jquery api -> val()