Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

devkon98's avatar

Javascript variable comes null even though it has one

Hello im using javascript to add parameters to an url, this is my code what i have done until now:

var startdate = document.getElementById("startdateOutlay"); var enddate = document.getElementById("enddateOutlay");

    alert(startdate.value);
    const apiUrl = `http://127.0.0.1:8000/api/outlay?startdate=${startdate.value}&enddate=${enddate.value}`;

the alert brings me the value correct but then on the url i get this error:

Uncaught (in promise) TypeError: startdate is null

0 likes
1 reply

Please or to participate in this conversation.