APIs & Integrations

Hubsforero
Contributor

Problem with de ID property of the fields in a form

SOLVE

 

    Hello partners!

 

    I realised that the "ID" property have change and now they vary everytime you open a landing page. It used to always have an fixed ID with the form number and now it has atached 4 numbers at the end, wich they change every time you refresh the page?

 

   I use the ID with the classical document.getElementById....

 

   Someone knows what will happen with my old landing pages? Will their forms change too?

 

  Thanks in advance.

0 Upvotes
1 Accepted solution
Hubsforero
Solution
Contributor

Problem with de ID property of the fields in a form

SOLVE

    Hi!

 

    You are right! This number is only fixed in the exported forms (snipped code), not in the created from hubspot directly. I realised that after...

 

   Anyway, I've found a function to do the thing, you can see here:

https://www.webdeveloper.com/d/114892-getelementbyid-partial-ids

 

   Thanks for your help! Bye.

View solution in original post

0 Upvotes
2 Replies 2
lscanlan
HubSpot Alumni
HubSpot Alumni

Problem with de ID property of the fields in a form

SOLVE

Hi @Hubsforero,

 

I'm not sure if the digits at the end of the form ID you're referring to is a recent change; I could do some digging to see when that was added. Do you have a page where that's not happening? My understanding was that the ID attribute of a form on a page is going to be the form's actual ID, with those 4 digits appended. If you're looking for only the form ID, could you instead search by the data-form-id attribute? In jQuery that's pretty simple. You could do something like this:

 

$("[data-form-id='9dc26cae-b3ee-6bdc-9066-a299cf7e835b']")

 

Or in vanilla JS you could do something like this:

 

document.querySelectorAll("[data-form-id='9dc26cae-b3ee-6bdc-9066-a299cf7e835b']");

 

...which will return a NodeList that you can loop through. For what it's worth, there's a helpful Stack Overflow thread on grabbing elements by data attributes here: https://stackoverflow.com/questions/15912246/access-data-attribute-without-jquery

 

Does that help with what you're trying to do?

 

- Leland

Leland Scanlan

HubSpot Developer Support
0 Upvotes
Hubsforero
Solution
Contributor

Problem with de ID property of the fields in a form

SOLVE

    Hi!

 

    You are right! This number is only fixed in the exported forms (snipped code), not in the created from hubspot directly. I realised that after...

 

   Anyway, I've found a function to do the thing, you can see here:

https://www.webdeveloper.com/d/114892-getelementbyid-partial-ids

 

   Thanks for your help! Bye.

0 Upvotes