Problem with de ID property of the fields in a form

SOLVE
Regular Contributor

 

    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.

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Highlighted
Regular Contributor

    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.

Reply
0 Upvotes
2 Replies 2
HubSpot Moderator

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
Reply
0 Upvotes
Highlighted
Regular Contributor

    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.

Reply
0 Upvotes