You can see that the code to update the value of input box is not wrapped in an if statement, so it changes the value of input box even if a date is already entered in the box. I would expect something more like this: