How to check column in editable datatable?

I am using an editable HTML file located on my asp.net webpage. It looks like this, enter image description here

How to add validation in the Target column to get only float values?

Function (to enable editing):

function editRow(oTable, nRow) { var aData = oTable.fnGetData(nRow); var jqTds = $('>td', nRow); jqTds[0].innerHTML = aData[0]; jqTds[1].innerHTML = aData[1]; jqTds[2].innerHTML = '<input type="text" id="Float" class="form-control" value="' + aData[2] + '">'; jqTds[3].innerHTML = '<a class="save-row" href="">Save</a>'; jqTds[4].innerHTML = '<a class="cancel-row" href="">Cancel</a>'; } 

I tried adding a keypress event to the text box, but its not working.!

 $('#Float').keypress(function (event) { if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57) && (event.which != 8)) { event.preventDefault(); } }); 

I'm new to jquery, so please help me solve this problem?

+5
source share
1 answer
 Try: onload =function(){ var ele = document.querySelectorAll('.number-only')[0]; ele.onkeypress = function(e) { if(isNaN(this.value+""+String.fromCharCode(e.charCode))) return false; } ele.onpaste = function(e){ e.preventDefault(); } } Note: Above code doesn't work for -ve values. 
+1
source

Source: https://habr.com/ru/post/1271135/


All Articles