I built a website for a client about 9 months ago, with intermediate Webflow skills and beginner Javascript skills. Somewhere along the line I managed to integrate this Javascript library ~ which I found used in this Webflow showcase project to successfully add dropdown to select a country code for a phone number. This is important to the client because apparently they get a lot of submissions where users neglect to add the country code to the their phone number.
I successfully added it on this page and now I want to add the same plugin on another page ~ but the trouble is, it was a while ago and I don’t quite remember how I got it working, and the documentation on the plugin’s GitHub isn’t really helpful.
What I can gather from the structure of the working page is that the plugin uses a hidden input (which is in an HTML embed just before the input with the is of PHONE ~ as well as adding the script to the page.
Side note: is putting the script in an embed at the bottom of the navigator the same as putting it in the Page Settings under before </body>? My limited knowledge of coding tells me that those two options would be identical, but I can’t put it in the page footer because there’s a lot of code there already.
I’m trying to add the country code select to the form on this page - (click through to the phone# input on the last page before Submit) — but it isn’t working for me.
If anyone could take a look and help me out, I’d be very appreciative and could write a full post with detailed information on how to achieve this, and hopefully the comunity would benefit.
I copied the original code from the project you linked and changed the ‘input’ variable to ‘phoneInput’ as I think it was clashing with some of your other code. Managed to get it working on my end - screenshot here.
Would you mind sharing your process of how you figured out there was a conflict?
So the problem was just with my page? Maybe a variable with the same name input?
It was kind of lucky actually - the first thing I did was console.log(input) to make sure that the code was finding the field and I got ‘input is not defined’, I tried the same thing on the special-offers page and the cloneable and they both returned the correct input so I guessed that it might be clashing with another variable.
I definitely need to learn more Javascript… But should already know enough that the console should be the first place to go ~ I feel like that’s both the blessing and curse of Webflow - it makes things much easier to learn, but then you sort of escape some basics that might cause you errors…
I’m thinking of writing up a post for the Webflow blog that helps with some of these pitfalls that I’ve encountered - thanks a lot for your help!