I’m trying to run a ts/js file from a button in an HTML file.
I’m using TS and node js.
this is a bit of code where I get the error
document.addEventListener('DOMContentLoaded', () => {
const saftbutton = document.getElementById('xbutton') as HTMLButtonElement;
xbutton.addEventListener('click', async () => {
try {
const startdateInput = document.getElementById('startdate') as HTMLInputElement;
const enddateInput = document.getElementById('enddate') as HTMLInputElement;
const startDate = startdateInput.value;
const endDate = enddateInput.value;
console.log('Start Date:', startDate);
console.log('End Date: ', endDate);
const response = await fetch('/prog/callback',
{
method: 'POST',
headers:
{
'Content-Type': 'application/json'
},
body: JSON.stringify({
startDate,
endDate
})
}
);
await start(2);
and this is the error I get:
document.addEventListener('DOMContentLoaded', () => {
^
ReferenceError: document is not defined
can someone help me with this?
Thanks
New contributor
cesar lapa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.