I have this function :
function getlst() {
$.ajax({
type: "GET",
url: "/api/Configuration/GetListParameter",
success: function (data) {
EmptyGridStep1();
for (var i = 0; i < data.length; i++) {
$('#tableBody').append('<tr><td><label id="id" name="id" >' + data[i].id + ' </td>'
+ '<td>' + data[i].key + '</td>'
+ '<td><input type="text" onchange="keydown();" value="' + data[i].value + '" /></td></tr>');
}
initGrid();
}
});
}
The Keydown function
function keydown(value )
{
alert(value);
}
I'd like to change :
<td><input type="text" onchange="keydown();" value="' + data[i].value + '" /></td>
To pass the current text as a paramater to keydown function.
How can I modify my code to accomplish this task?
You don't have to do so. All you have to do is pass the input itself as a parameter to your keydown function
<td><input type="text" onchange="keydown(this);" value="' + data[i].value + '" /></td>
and just read its value here
function keydown(input)
{
alert(input.value);
}
Not the most elegant way to do it, I suggest instead of using onchange, you use jquery's change event , so you have one single listener for your change event
$('#tableBody').on("change", "input", function() {
console.log( this.value );
});
You should read this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With