I am currently facing an issue with retrieving the value of a textarea that I have dynamically added to a fieldset in my form. When I attempt to submit the form, the code below is executed:
function handleSubmit(e) {
e.preventDefault();
console.log(document.getElementById('Observation_1').value);
const data = new FormData(e.target);
const value = data.get('Observation_1');
console.log(value);
}
const form = document.querySelector('form');
form.addEventListener('submit', handleSubmit);
<form>
<textarea id="Observation_1"></textarea><br>
<button type="submit">Test</button>
</form>
However, after execution, console.log (value);
shows null, whereas
console.log(document.getElementById('Observation_1').value);
displays the correct content of the textarea.
I would appreciate if someone could clarify why I am getting a null return and offer a solution to rectify this issue so that I can obtain the actual content of my textarea. Thank you.