how to insert javascript script in formidable form?

By: NDIFFO Marcelin | Asked: 11/10/2024
ForumsCategory: Code Snippetshow to insert javascript script in formidable form?
NDIFFO Marcelin asked 1 month ago
drop-down list field names: Allocated space, Subscription duration
product field name: My subscription I have a problem with the creation of my form on formidable: i have a drop-down list field "allocated space" (200 GB, 500 GB, 1TB) another subscription duration (3 months, 6 months, 12 months), another that sets the prices in my subscription with the base price 3 months at €35 for a storage of 200 GB. how to create the conditions for the rest in order to automate the process? unfortunately formidable form does not allow to create conditional logic with 2 fields like If “allocated space” is “200 GB” and “duration” is “3 months”, then the price is 35.

by doing some google searches I read that I could add code snippet with the wpcode plugin. here is my code used
document.addEventListener('DOMContentLoaded', function() {
var espaceAlloue = document.querySelector('[name="Espace réservé"]');
var durée = document.querySelector('[name="Durée de l\'abonnement"]');
var prix = document.querySelector('[name="Mon abonnement"]'); function updatePrix() {
var espaceValue = espaceAlloue.value;
var duréeValue = durée.value;
var prixValue = 0; if (espaceValue === '200 Go') {
if (dureeValue === '3 mois') {
prixValue = 35;
} else if (dureeValue === '6 mois') {
prixValue = 35 * 2 - 5; // Example of discount for 6 months
} else if (durationValue === '12 months') {
priceValue = 35 * 4 - 10; // Example of a discount for 12 months
}
} else if (spaceValue === '500 GB') {
if (durationValue === '3 months') {
priceValue = 50; // Example of a price for 500 GB and 3 months
} else if (durationValue === '6 months') {
priceValue = 50 * 2 - 10; // Example of a discount for 6 months
} else if (durationValue === '12 months') {
priceValue = 50 * 4 - 20; // Example of a discount for 12 months
}
} else if (spaceValue === '1 TB') {
if (durationValue === '3 months') {
priceValue = 70; // Example of price for 1TB and 3 months
} else if (durationValue === '6 months') {
priceValue = 70 * 2 - 15; // Example of discount for 6 months
} else if (durationValue === '12 months') {
priceValue = 70 * 4 - 30; // Example of discount for 12 months
}
} price.value = priceValue;
} espaceAlloue.addEventListener('change', updatePrix);
duree.addEventListener('change', updatePrix);
}); but after saving and activating it did not have effect
1 Answers
Rob LeVineRob LeVine answered 1 month ago
Follow the directions at the top of this page as to where to put your code. Then you can use the browser debugger to step through your code.
NDIFFO Marcelin replied 3 weeks ago

Hello, and thank you for your help.

Unfortunately, I can't accomplish my task with the example you provided. Isn't there another approach?

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right