How do I make the text input remain selected after I click enter (enter adds the input text to a task list)

Asked

Viewed 22 times

-1

Entire list
<main id="base_list">

    <div id="title_list"><p id="title_text">ToDo list</p></div><!--TITLE LIST-->

    <form id="input_back" >
        <input id="add_list" type="text" placeholder="type your tasks here and press enter..."><!--INPUT TO TYPE YOUR NOTES-->
    </form>

    <div class="todo_list" id='todoList'>
        
    </div><!--ADDED LIST-->

</main>
<script src="script.js"></script>
  • creates an action for the event keypress for example, do what you want and keep Focus in the field

  • beauty, thanks in.

1 answer

-1

You can use .focus() at the end its inclusion function, do not know how is your script, but I believe it treats the inclusion of data in the list.

Using the onkeypress to call its function, treating it to perform the inclusion only when the key is pressed enter. Otherwise, each key you press while typing will perform the inclusion. And at the end of the inclusion, call focus() for his input.

In this way, for example:

document.getElementById('add_list').focus();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.