-1

hello I made a to do list app and I want to clear input after submit here is my code but it doesn't workenter image description here

I expect input section to be null after I submit but every time I have to use backspace then write a new task

selma
  • 1
  • Please [edit] your question and provide a [mre] (this means, your _code must be in the question itself, as [formatted text](//meta.stackoverflow.com/q/251361/4642212) and [**not** a picture](//meta.stackoverflow.com/q/285551/4642212)_), along with your _desired_ results, your _actual_ results, including all _errors_, and demonstrate _your research and your attempts_ and explain what precisely didn’t work. Use the [browser console (dev tools)](//webmasters.stackexchange.com/q/8525) (hit `F12`), read any errors. – Sebastian Simon Jan 28 '23 at 08:21
  • You should provide code in order to debug – Anuj Shaan Jan 28 '23 at 08:27
  • Learn about [how to debug small programs](//ericlippert.com/2014/03/05/how-to-debug-small-programs). See [If a variable is defined in terms of another, can it reflect changes in the binding of the other?](/q/42637782/4642212); reassigning a variable will never cause anything to mutate, including the DOM. That’s not how JavaScript works. Duplicate of [Setting innerHTML: Why won't it update the DOM?](/q/8196240/4642212). – Sebastian Simon Jan 28 '23 at 08:28

2 Answers2

0

First, I would change class="myinput" to id="myinput".

You are assigning user_input to the value of the input at that moment.

Replace your code line to get value by id:

let user_input=document.getElementById("myinput");

let user_input_value=user_input.value;

compare: if(user_input_value!='')

clear with: user_input.value='';

Vbudo
  • 405
  • 4
  • 9
0

Hi

You just need to save the input element in a variable and set the value property to empty string rather than directly setting user_input = ''. Also, unless there many inputs you need to loop through, it's better to use id and document.getElementById to identify the input you want rather than document.querySelectorAll

  1. Save the input element as const
const user_input = document.getElementById('myInputId');
// get the value and use as needed
let user_input_value = user_input.value;
  1. After, when you need to reset, set the input elements value to ''
user_input.value = '';
spc
  • 447
  • 2
  • 6