I am very new to JS and HTML, so my apologies. I have run into trouble trying to validate input into a form field with the pattern='' attribute. Although it catches invalid input and gives the appropriate error message, subsequent modifications of the input do not change the error message. For example,
pattern="[a-zA-Z]" will produce the appropriate message if the user enters "testing2" into the field. But if the user edits the entry to "testing" I still get a validation error.
In trying to figure this out, I tried to log the field input to the console. So, in the HTML:
<input class="dest_one_key" name="dest_one_key" type="text" id="dest_one_key" required="" placeholder="Work">
and then:
<script>
var v = document.getElementById('dest_one_key').value;
document.getElementById('dest_one_key').addEventListener('change', function() {
console.log(Value: ${v});
});
</script>
...which yeilds
"Value: "
in the console. So the form does not seem to be capturing the users input.
What I'm doing wrong with respect to: 1) Not being able to properly register that the user has a valid input after an invalid input 2) logging the value of the field to the console?
keyupevent to log each time the user inputs something new. here is an example: jsbin.com/natociy/4/edit?html,js,output