# Wine calculator

**URL:** <https://forum.bootstrapstudio.io/t/wine-calculator/11791>\
**Category:** Showcase\
**Created:** [November 17, 2024, 10:28pm UTC](https://forum.bootstrapstudio.io/t/wine-calculator/11791 "2024-11-17T22:28:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hybataa](https://forum.bootstrapstudio.io/letter_avatar_proxy/v4/letter/h/c89c15/32.png) [@hybataa](https://forum.bootstrapstudio.io/u/hybataa)\
**Post date:** [November 17, 2024, 10:28pm UTC](https://forum.bootstrapstudio.io/t/wine-calculator/11791/1 "2024-11-17T22:28:39Z")

</div>

A small website with a wine calculator for determining the amount of sugar added to fruit wine. (Fruits other than grapes contain too little sugar and are usually sweetened.)

 ![](https://forum.bootstrapstudio.io/uploads/default/original/2X/7/70e64d785e2b9a030d0d62d01f69efcbec96cf29.png)  
[Wine calculator](https://nalewkidomowe.com/kalkulator-winiarski)  
Good result in PageSpeed ​​Insights 🙂

---

<div class="post-metadata">

**Author:** ![hybataa](https://forum.bootstrapstudio.io/letter_avatar_proxy/v4/letter/h/c89c15/32.png) [@hybataa](https://forum.bootstrapstudio.io/u/hybataa)\
**Post date:** [November 25, 2024, 10:10pm UTC](https://forum.bootstrapstudio.io/t/wine-calculator/11791/2 "2024-11-25T22:10:49Z")

</div>

I also expanded the page with information about its use, cleverly hidden in the accordion 🙂

I have one more little problem:

The results (numbers) that are displayed have a predetermined space. With a small number there is a large space, with a large number there is no space.

 ![wynik max](https://forum.bootstrapstudio.io/uploads/default/original/2X/d/d8be9626ebcce8b7a045654066b194aeec680bcd.jpeg)

This is a piece of code:

```auto
        <tr>
         <td>
           <strong>Dodając</strong> <input id="type1" size="2" name="g" placeholder=" ? ">
           <strong>gramów cukru otrzymasz <input id="type2" size="2" name="s" placeholder=" ? ">litrów wina<br><br><hr></strong>
         </td>
        </tr>
       </div>
Do you have an idea on how to make it flexible? Thank you.
```

---

<div class="post-metadata">

**Author:** ![richards](https://forum.bootstrapstudio.io/user_avatar/forum.bootstrapstudio.io/richards/32/3163_2.png) [@richards](https://forum.bootstrapstudio.io/u/richards)\
**Post date:** [November 27, 2024, 2:05pm UTC](https://forum.bootstrapstudio.io/t/wine-calculator/11791/3 "2024-11-27T14:05:38Z")

</div>

Give each of your inputs that you want ‘responsive’ a class of responsive-input

then use the following JS:

```auto
// Select all inputs with class "responsive-input"
const responsiveInputs = document.querySelectorAll('.responsive-input');

// Function to set width based on value length
function setResponsiveInputWidth(input) {
  const valueLength = input.value.length; // valueLength = length of the current input
  input.style.width = `calc(${valueLength}ch + 6px)`; // you may want to change the 6px to suit your design
}

// Add event listeners
responsiveInputs.forEach(input => {
  input.addEventListener('input', () => setResponsiveInputWidth(input));
  input.addEventListener('DOMContentLoaded', () => setResponsiveInputWidth(input));
});

 

```

you may need to adapt the code to run when your calculations are completed

CSS

```auto
.responsive-input {
  border: 0;
  text-align: center;
  width: calc(3ch + 6px);
}

```

Alternatively you could just use spans rather than inputs

---

<div class="post-metadata">

**Author:** ![hybataa](https://forum.bootstrapstudio.io/letter_avatar_proxy/v4/letter/h/c89c15/32.png) [@hybataa](https://forum.bootstrapstudio.io/u/hybataa)\
**Post date:** [November 30, 2024, 10:22am UTC](https://forum.bootstrapstudio.io/t/wine-calculator/11791/4 "2024-11-30T10:22:44Z")

</div>

Richards, thank you very much for writing the code in js and for the detailed comments.

Yesterday I found on the internet that the OUTPUT command was introduced in 2020 - this simplified things a lot.

Thank you again, now everything works as I wanted.
