Not getting access to Hubspot embedded form's field



I am trying to set value of firstname input field by using getElementByID but it is does not find the element.

I have tried it in a script that loads after window.load, waiting for the form to build.

Whatever I try I am not able to get access to the element.

var str; if (document.getElementById('firstname-5482418a-dc34-4367-baa5-410973f76e13') != null) { str = document.getElementById("firstname-5482418a-dc34-4367-baa5-410973f76e13").value; alert(str); } else { str = null; alert(str); } This script returns null. Please help


Hi @Bhavin_Bhatt,

This is working for me when I test it. Would you have an example URL I can take a look at to see what might be going on?


   	var str = $('input[name="firstname"]').val();

Firstname is the actual name of the field in Hubspot. See below: name=“firsthame”

<input id="firstname-05f8f863-0a27-4b01-afe9-fcb8f77807fa" class="hs-input" type="text" name="firstname" required="" value="Jason" placeholder="" data-reactid=".0.0:$6.1:$firstname.$firstname.0">