Get updated value from input field
Get updated value from input field

Hello Team,
I have columns defined like this.
I'm trying to retrieve the updated value on the 'qty' filed when it is updated.
columns: [{ data: 'idnum' },
{ data: 'productid' },
{ data: 'qty', "defaultContent": '<input type="number" id="qtybtn" value="0" min="0" max="100" step="1"/>', attr: {type: "number"}}
],
I have tried a few things as below but it always gives me the first rows values.
$(document).ready(function () {
var table = $('#wscarttable').DataTable();
$('#wscarttable tbody').on('click', '#qtybtn', function () {
console.log(table.$('#qtybtn').val());
console.log(document.getElementById("qtybtn").value)
});
});
This question has accepted answers - jump to:
This discussion has been closed.
Answers
One problem is this:
ids should be unique on the page - for you, every record would have a cell with the same id, which isn't valid HTML.
If that doesn't help, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Thank your for your response @colin
I removed
id="qtybtn"
Here is a sample test case demonstrating the scenario.
The issue is, i am unable to retrieve the the input field 'qty' at all.
What i need is, get all table data including the current/updated value of 'qty' input field.
Thanks.
Yep, you need to get the node of the cell, and then the
val()
of theinput
element - see here.Colin
@colin , Excellent !! That did the trick. Thank you very much !!
I have one last follow up question to my initial requirement of having an event, either click or change in the input field.
I basically want to update a another column in the table when the value in the input field changes.
Here is a test case demonstration which is not working.
Thanks
You are getting this error:
this
is thetbody
element which does not have.index()
as a function and is not useable as arow-selector
. Change thekeyup
event selector to$("#example tbody tr")
and the value ofthis
will be thetr
which can be used as the selector. Here is the updated example:http://live.datatables.net/gobigupa/3/edit
Kevin
@kthorngren That worked perfectly !! Thank you so much for the explanation and the example.