Arthur2465 Posted December 29, 2022 Share Posted December 29, 2022 Hi! I have a function in my footer, which looks like that: <script> function rolls() { var totalrolls = Math.ceil(((document.input.input2.value -0) + 53) * (document.input.input1.value -0) / 50000) ; document.getElementById('txtrolls').innerText=totalrolls; } </script> Then I want to set up a form using Squarespace form block (in lightbox mode) to collect "input1" and "input2" as input fields, and upon submission of the form, call the function "rolls()" and show the value "totalrolls" in the post submit message. I name the Form Fields "input 1" and "input 2", but how to call "rolls()" upon submission? Or should I call the function in the Post-Submit HTML and show the value there as well? I don't have it on my website yet (so no link to show) as I am not sure if this is feasible and how.. Thanks for your help! Link to comment
Wolfsilon Posted December 30, 2022 Share Posted December 30, 2022 The difficulty is that Squarespace will load everything immediately on render, this means it will also run the script you've shown above. If you're familiar with JS you can try to disable AJAX loading. In my opinion, the result of doing so is almost worse than if you left it on. The simplest solution is to avoid relying on inputs or interactions to fire an event, especially if we have no control over it. Similarly, because we have no control over the Form script, it'd be safe to assume we also can't adjust that code at that level either. I'd suggest building the 'webapp' yourself, if you're comfortable, or seeing if there's a third-party widget that you can use. Link to comment
Arthur2465 Posted January 1 Author Share Posted January 1 Thanks @Wolfsilon! Is there a code to show a simple Lightbox popup that would look like the Squarespace form? As such I could do my own form and run the calculation above. I find expansive plugins doing stuff I don't need or the jQuery lightbox plugin. But is it possible to replicate the Form lightbox with a simple code? Many thanks Link to comment
sorca_marian Posted September 12 Share Posted September 12 You can do that with custom code. To run JavaScript after a Squarespace form was submitted you can check the below video and here are the codes https://github.com/sorcamarian/squarespace-tricks/tree/main/Forms Contact me for development work - I’m a Freelancer Software engineer and architect Squarespace Tutorials for free - YouTube📹 Manage Tasks & Notes Easily Squarespace Custom Web Development & Design 😀 Message me if you need custom features or a new website created Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment