Unverified

Name

Calculated-Checkbox

Language

HTML

Rating

Voted: 0 by 0 user(s)

Codevault

WebSquadron

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

10/08/2024

Important Note

This snippet has the following status:

Unverified

This snippet has not been verified, use with caution and at your own risk. See details provided by author in sidebar and click below to find out more.

Calculated-Checkbox

 
                    
1<script>
2document.addEventListener('DOMContentLoaded', function() {
3 const optionsField = document.querySelectorAll('input[name="form_fields[options][]"]');
4 const totalField = document.getElementById('form-field-total');
5 
6 function getOptionPrice(option) {
7 switch(option) {
8 case 'Option 1 - $5':
9 return 5;
10 case 'Option 2 - $10':
11 return 10;
12 case 'Option 3 - $15':
13 return 15;
14 case 'Option 4 - $20':
15 return 20;
16 case 'Option 5 - $25':
17 return 25;
18 default:
19 return 0;
20 }
21 }
22 
23 function calculateTotal() {
24 let total = 0;
25 optionsField.forEach(function(option) {
26 if (option.checked) {
27 total += getOptionPrice(option.value);
28 }
29 });
30 totalField.value = `$${total.toFixed(2)}`;
31 }
32 
33 // Add event listeners to checkboxes
34 optionsField.forEach(function(option) {
35 option.addEventListener('change', calculateTotal);
36 });
37 
38 // Initial total calculation
39 calculateTotal();
40});
41</script>

0

Related Snippets

Please see some snippets below related to this snippet..

Elementor

Public

0

Moves image to top of 'classic' layout (on mobile) when using Elementor post widget

Added: 2 years ago

Last Updated: 1 year ago

If you are using the classic layout for Elementor post widget with the image set to left or right, you cannot change the position of the image on mobile. If you have an lengthy excerpt or title it loo...

Elementor

AI Verified

0

Stop-FOUC

Added: 2 months ago

Last Updated: 2 months ago

Elementor

Unverified

5

Elementor Gradients Headings

Added: 2 years ago

Last Updated: 3 months ago

CSS Code for background gradients on headings in Elementor

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

35

Remove Unused Javascript

Added: 2 years ago

Last Updated: 1 week ago

Remove Unused Javascript - and improve your Page Speed Insight Score

WooCommerce

Pro Verified

10

Deactivate some WooCommerce Checkout Fields

Added: 2 years ago

Last Updated: 2 months ago

Deactivate some WooCommerce Checkout Fields from showing

Elementor

AI Verified

6

CSS Grid Aid

Added: 9 months ago

Last Updated: 3 months ago

This can be used for any WordPress Builder to aid working with CSS Grids.