Okay .. this is my attempt to execute a function instead of calling from it from the tag .. thing is .. it's not working .. mind you I'm still fresh with all these sigh
<div class="widget first"> <div class="head"><h5 class="iFrames">Static table</h5></div> <table id="example" cellpadding="0" cellspacing="0" width="100%" class="tableStatic"> <thead> <tr> <td width="20%">Column 1</td> <td width="20%">Column 2</td> <td width="20%">Column 3</td> <td width="20%">Column 4</td> <td width="20%">Column 5</td> </tr> </thead> <tbody> </tbody> </table> </div> <input type="text" name="name" id="name" /> and the script would go:
/* Global var for counter */ var giCount = 1; $(document).ready(function() { $('#example').dataTable(); } ); function fnClickAddRow() { $('#example').dataTable().fnAddData( [ $("#name").val(), giCount+".2", giCount+".3", giCount+".4", giCount+".5" ] ); $("#name").val('').focus(); giCount++; } $('#name').on('keyup', function(e) { var code = (e.keyCode ? e.keyCode : e.which); if (code == 13) { fnClickAddRow(); } }); Now, I'm trying to add new row with the value of "name" from the input upon entering. And it's not working :\ .. by the way in this example I'm using DataTables ...
(e.keyCode ? e.keyCode : e.which)jQuery already normalizes it withe.whiche.whichis enough if you use jQuery.