Assuming you have your elements wrapped in a form
, this happens because named elements are added as properties to the form
.
When you were trying to call newTreatement
, there already existed a property newTreatment
in that scope. It thought you were referring to the property and gave you an error of
newTreatment is not a function
See Why JS function name conflicts with element ID? and Do DOM tree elements with ids become global variables?