Filling Input field using js

I'm trying to fill the hidden input field in hubspot form
<input name="last_visited_url_before_demo" class="hs-input" type="hidden" value="">


tried using this code
document.addEventListener('DOMContentLoaded', function() {
    const inputField = document.querySelector('.hs_last_visited_url_before_demo input');
    const url = "theurl.com";
    inputField.value = url;
});

Codepen: https://codepen.io/Abdul-Ahad-the-decoder/pen/KKYYyod?editors=1010

i'm not sure, what's going wrong here, can you please help
Was this page helpful?