The errors are happening because Windows Script Host isn’t the same as a browser. WSH only runs old-style JScript and doesn’t provide a DOM, so functions like document.createElement() or form.setAttribute() won’t work there.
If you want to build and manipulate forms with JavaScript, you’ll need to run the code inside a browser. A simple setup would be:
- Create an
index.htmlfile:<!DOCTYPE html> <html> <body> <div id="container"></div> <script src="script.js"></script> </body> </html> - Put this into
script.js:
const form = document.createElement('form');
form.setAttribute('id', 'myForm');
document.getElementById('container').appendChild(form);
If you’d like to see a working example of this kind of setup in practice, here’s an example sitethat builds its interface with nothing more than HTML, CSS, and JavaScript.