el mensaje de error que me sigue apareciendo Uncaught TypeError: form.querySelector(...) is null todo funcionaba bien hasta hace un tiempo, así que debo haber cambiado algo que no sé sobre file:///C:/Users/Ben /Documentos/descargar archivo de texto/v12/prueba v12 .html:35
<html> <form name="addtext"> <table> <tr> <tr> <th> Fan Delay </th> <th><input id="fanDelay" type="text" name="fanDelay" value="0" /></th> </tr> </table> <table class="center"> <th></th> <th> <input type="submit" name="name" value="Save File" placeholder="File Name" /> </th> </table> </form> </html> <script> /* Run script after DOMContentLoaded event to ensure form element is present */ document.addEventListener("DOMContentLoaded", function() { /* Obtain form element via querySelector */ const form = document.querySelector('form[name="addtext"]'); /* Bind listener to forms submit event */ form.addEventListener("submit", function(event) { /* Prevent browsers default submit and page-reload behavior */ event.preventDefault(); var fanDelay = form.querySelector('select[name="fanDelay"]').value; // const text = `TACm Settings VER PRO dt: ${fanDelay} `; /* Create temporary link element and trigger file download */ const link = document.createElement("a"); const href = "data:text/plain;charset=utf-8," + encodeURIComponent(text); link.setAttribute("href", href); link.setAttribute("download", "usb.txt"); document.body.appendChild(link); link.click(); document.body.removeChild(link); }); }); </script>Creo que el error viene de aquí form.querySelector('select[name="fanDelay"]').value
Está utilizando la etiqueta <input> , así que simplemente cámbiela a form.querySelector('input[name="fanDelay"]').value
usted está tratando de queryselector una select en lugar de input
prueba esto :
var fanDelay = form.querySelector('input[name="fanDelay"]').value;