-5

How to get data from input without refresh, form, and submit button (jquery & ajax) like comment facebook ?

Get data when input on enter.

<body>
<input class="form-control input-sm" id="komentar" type="text">
<script>
$('#komentar').submit(function() {
console.log($('#komentar').val());
});
</body>
Aditya
  • 61
  • 5

2 Answers2

0

Use keypress, if you want to get the data when user presses enter.

 <body>
    <input class="form-control input-sm" id="komentar" type="text">
    <script>
       $('#komentar').keypress(function(e) {
        if(e.which == 13) {
           console.log($('#komentar').val());
        }});
    </script>
 </body>
Rakesh Nair
  • 1,083
  • 3
  • 21
  • 30
0

Submit will do the post back. So, we need to use click() instead of submit as below

`<script>
    $('#komentar').click(function(){
       console.log('');
    });
</script>`

Or use <button>INSTEAD OF INPUT</button> if possible

jithil
  • 651
  • 6
  • 8