-3

I'm making a Chrome Extension that acts as a task list. You can type in any task you want (ex. Buy eggs) and add it to your list. I wanted to allow the user to type in the task and press the "Enter" key to add it to the list. However, I saw that "keycode" has been removed, so I was wondering if there were any other possible solutions to this issue. I've tried using the method below:

    <input type="text" name="newtask" value="" spellcheck="false" placeholder="New Task" id="newtask">
    <script>
      var input = document.getElementById("newtask");
      input.addEventListener("keyup", function(event) {
        if (event.keyCode === 13) {
          alert('test');
          event.preventDefault();
      }
      });
    </script>

For now, I'm making it so that if the user presses enter in the input/text box, there will be an alert that states "test." However, when I press enter, nothing happens.

Aurora123
  • 135
  • 3
  • 13

1 Answers1

0

I think you should try this:

<input type="text" name="newtask" value="" spellcheck="false" placeholder="New Task" id="newtask">
<script>
var input = document.getElementById("newtask");
input.addEventListener("keypress",function() {
alert('test');
});
</script>

No need to add if statement try with keypress event

Ritesh Khandekar
  • 3,885
  • 3
  • 15
  • 30