Clear input field value with javascript

I’m experiencing some strang behaviour when trying to clear the value of a text input field. Let’s say the user types something into the below input field–which is part of a form. I would like to use javascript to clear the value in this field (I know I can use a reset button to accomplish this, my scenario is simply for examples sake so I can understand what is going on)


    <input type="text" value="" name="input1" id="input1">
    
    # This doesn't clear the value if the user has already
    # typed something into the field
    var input = document.getElementById("input1");
    input.setAttribute("value", "");
    
    # This will clear the value in all scenarious
    var input = document.getElementById("input1");
    input.value == ""
    
    # This will set the value only if the user hasn't 
  # already typed something into the field.
    var input = document.getElementById("input1");
  input.setAttribute("value", "A Value");
    
Can anyone explain this behaviour?

Thanks,
Steven

I think that if the user enters input, then the value attribute has a value, so it can not be set, as it already is set. Maybe something like this would work?

var input = document.getElementById("input1");
input_value =  input.getAttribute("value");
input_value = "";

Unfortunately you can not access value attribute directly.
However here is a little trick how to erase value: