0

I want to send my text by value by pressing enter instead of pressing buttun like the following,but how can i do it?

  $("#senddata").click(function () {
        var drp = document.getElementById('autocomplete').value; 

        $.ajax({
            dataType: "json",
            type: "POST",
            url: "@Url.Action("ID","AdminTool")",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify({ "turbine": drp,}),
Satpal
  • 132,252
  • 13
  • 159
  • 168
moris62
  • 983
  • 1
  • 14
  • 41
  • Possible duplicate of [How to detect pressing Enter on keyboard using jQuery?](https://stackoverflow.com/questions/979662/how-to-detect-pressing-enter-on-keyboard-using-jquery) – Samuil Petrov Jun 23 '17 at 09:09
  • You may want to rethink your use case because people use enter for a lot of things like selecting something in autocomplete or selecting from dropdown list. Besides that, you would only want the user to send data after filling the complete form. – kvn Jun 23 '17 at 09:09
  • 1
    Possible duplicate of [Submitting a form on 'Enter' with jQuery?](https://stackoverflow.com/questions/699065/submitting-a-form-on-enter-with-jquery) – Shubham Khatri Jun 23 '17 at 09:12
  • Onkeypress event check the button key code. If key code is of enter button then call the ajax. Enter keycode = 13 – Ashu Jun 23 '17 at 09:16
  • 1
    @samuil Petrov thanks a lot! – moris62 Jun 23 '17 at 12:13

0 Answers0