calculation on the web

All WYSIWYG Web Builder support issues that are not covered in the forums below.
Forum rules
IMPORTANT NOTE!!

DO YOU HAVE A QUESTION OR PROBLEM AND WANT QUICK HELP?
THEN PLEASE SHARE A "DEMO" PROJECT.



PLEASE READ THE FORUM RULES BEFORE YOU POST:
http://www.wysiwygwebbuilder.com/forum/viewtopic.php?f=12&t=1901

MUST READ:
http://www.wysiwygwebbuilder.com/getting_started.html
WYSIWYG Web Builder FAQ
Post Reply
Joan Ferrer
 
 
Posts: 121
Joined: Sat Apr 25, 2020 5:17 pm
Contact:

calculation on the web

Post by Joan Ferrer »

Hello, I need to do a calculation on the web, is there any information available with examples?
Thank you.
Joan
User avatar
BaconFries
 
 
Posts: 6057
Joined: Thu Aug 16, 2007 7:32 pm

Re: calculation on the web

Post by BaconFries »

I need to do a calculation on the web,
Very vague question would really depend on what you're wanting to calculate is it just a simple 1+1=?
See the following:
Form Conditions and Calculations
Or something like
volume calculator for width, length and depth
Joan Ferrer
 
 
Posts: 121
Joined: Sat Apr 25, 2020 5:17 pm
Contact:

Re: calculation on the web

Post by Joan Ferrer »

Hi
For now, it is a generic question, but especially it is for calculating units of products with prices, with their possible variables.
Tnk's
User avatar
onlye
 
 
Posts: 473
Joined: Sun Jun 17, 2018 12:36 am
Location: Gluckstadt, MS USA
Contact:

Re: calculation on the web

Post by onlye »

Joan Ferrer wrote: Tue Sep 16, 2025 6:21 am Hi
For now, it is a generic question, but especially it is for calculating units of products with prices, with their possible variables.
Tnk's
for that application an ecommerce could work? phpjabbers stiva cart is possible, plus a number of wizzy options.
onlye
Gluckstadt, MS USA
User avatar
BaconFries
 
 
Posts: 6057
Joined: Thu Aug 16, 2007 7:32 pm

Re: calculation on the web

Post by BaconFries »

Maybe the following is what you are referring to. I do not take any credit for this it is provided as just an example to what I think you are asking.

For testing on a new blank workspace simply copy all of it and insert using Page HTML Between the <body></body> tags*

Code: Select all

<p>Select a product and the total amount you have to see how many units you can buy.</p>

    <label for="productSelect">Choose a Product:</label>
    <select id="productSelect">
        <option value="1.25">Pencil ($1.25)</option>
        <option value="0.75">Eraser ($0.75)</option>
        <option value="5.50">Notebook ($5.50)</option>
        <option value="2.00">Pen ($2.00)</option>
    </select>
    
    <br><br>

    <label for="amountSelect">Choose your Total Amount:</label>
    <select id="amountSelect">
        <option value="10"> $10.00</option>
        <option value="25"> $25.00</option>
        <option value="50" selected> $50.00</option>
        <option value="100">$100.00</option>
    </select>
    
    <hr>

    <div id="results"></div>

<script>
        // Get references to the select elements and the results div
        const productSelect = document.getElementById('productSelect');
        const amountSelect = document.getElementById('amountSelect');
        const resultsDiv = document.getElementById('results');

        // Function to perform the calculation and update the display
        function updateCalculation() {
            // Get the selected values from the dropdowns
            let unitPrice = parseFloat(productSelect.value);
            let totalAmount = parseFloat(amountSelect.value);

            // Calculate the total units
            let totalUnits = totalAmount / unitPrice;
            let wholeUnits = Math.floor(totalUnits);

            // Clear any previous results
            resultsDiv.innerHTML = '';
            
            // Create a new paragraph element to display the result
            const paragraph = document.createElement('p');
            paragraph.innerHTML = `With <b>$${totalAmount}</b> and a unit price of <b>$${unitPrice}</b>, you can buy <b>${totalUnits.toFixed(2)}</b> units.`;
            resultsDiv.appendChild(paragraph);

            // Create another paragraph for the whole units
            const wholeParagraph = document.createElement('p');
            wholeParagraph.innerHTML = `You can buy <b>${wholeUnits}</b> full units.`;
            resultsDiv.appendChild(wholeParagraph);
        }

        // Add event listeners to both dropdowns
        // The updateCalculation function will run whenever a user changes a selection
        productSelect.addEventListener('change', updateCalculation);
        amountSelect.addEventListener('change', updateCalculation);

        // Run the function once on page load to display the initial result
        updateCalculation();

    </script>
****Note just a Example****
Post Reply