I am trying to reset an input field using Java Script and it does not work in the way I intend to. I am trying to undestand why it works in a certain way and not in another way. Could you please explain why and provide any pointers if possible. Thank you.
Input text field I am trying to reset:
<input type="text" id="textInput" class="inp">
I defined a button like this:
<button id="resetButton">Reset</button>
I created an event listener on the reset button and used it like below.
var rButton=document.getElementById("resetButton");
rButton.addEventListener("click", function() {
var inputTextValue=document.getElementById("textInput").value;
inputTextValue="";
});
This is the JS code I am getting the value from the input text:
var inputTextValue=document.getElementById("textInput").value;
And to reset the value, I am just assigning it to empty string:
inputTextValue="";
This piece of code doesn't work but when I try to get the reference of the input text like this -
var inputText=document.getElementById("textInput");
and try to reset the value like this, it works -
inputText.value="";
So, I am trying to understand, what is the difference in both ways and what am I doing wrong.
.valueproperty to"".