Help me with T-shirt calculation

Please help me make right calculations for tshirt size calculator with sizes from 2 year, 4 year, 6 year, 8 year, 10 year, 12 year, XS, S , M, L , XL, XXL, 3XL, 4XL, regards to my size charts.

1 Like

1 Like

Hi there and welcome to the Community, @Tural_Aliyev :waving_hand:

Sure, I’ve passed your request to the devs and will let you know once the formula is created :slightly_smiling_face:

Hi there, @Tural_Aliyev :waving_hand:

Thank you for waiting!

We’ve noticed that in your widget, you’ve added 2 fields: Waist Circumference and Chest Circumference. Based on the tables you’ve shared, value A is body length, but not Chest Circumference.

Do you want to create to use body length and waist circumference in your widget with the values from your table? If you want to use chest circumference rather than body length, could you please share the values for all sizes?

Good day,
Yes need based on length please. :folded_hands:

чт, 22 мая 2025 г., 13:34 Max via Elfsight Community <notifications@elfsight.discoursemail.com>:

1 Like

Thank you!

We’ve customized your 2 Calculator widgets the way you’ve requested. Here is what’s been done:

  1. We’ve changed field labels:

Chest Circumference (cm) → Body length (cm)
Measure around the widest part of your chest. → Measure the body length from the top of the shoulder to the bottom hem.

  1. min/max field values were replaced with the values from your table

  2. Since the text values are not supported in the results, we’ve added special scripts that will show the recommended size. These scripts were added to the Custom JS section on the Settings tab of your widgets’ settings.

Here is a script for the widget with English version:

function mapSize(n) {
  switch (n) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    case 7:
    case 8:
    case 9:
    case 10:
    case 11:
    case 12:
      return n + " year";
    case 13:
      return "XS";
    case 14:
      return "S";
    case 15:
      return "M";
    case 16:
      return "L";
    case 17:
      return "XL";
    case 18:
      return "2XL";
    case 19:
      return "3XL";
    case 20:
      return "4XL";
    default:
      return String(n);
  }
}

function attachObserver(node) {
  const mo = new MutationObserver(() => {
    const raw = node.textContent.trim();
    console.log("INSIDE", raw);
    if (!/^\d+$/.test(raw)) {
      return;
    }
    const num = parseInt(raw, 10);
    const label = mapSize(num);
    if (label !== raw) {
      node.textContent = label;
    }
  });

  mo.observe(node, {
    childList: true,
    characterData: true,
    subtree: true,
  });
}

new MutationObserver((mutations) => {
  mutations.forEach((mutation) => {
    if (mutation.type === "childList") {
      for (const node of mutation.addedNodes) {
        if (node.className && node.className.includes("es-embed-root")) {
          const calculations = node.querySelectorAll(
            '[class*="animated-number__Content-sc"]',
          );
          console.log(calculations);
          calculations.forEach(attachObserver);
        }
      }
    }
  });
}).observe(document.body, {
  childList: true,
  subtree: true,
});

Note: Custom JS scripts work only upon widget’s installation, not in the preview mode

  1. Added new formulas

Please check it out and let me know if you like the result :slightly_smiling_face:

2 Likes

And yes, we’ve saved changes in the widget, but haven’t published them. If you like how it looks, please publish changes and check the widget on your website :slightly_smiling_face:

please can you explain how and to where add this script please ?

1 Like

You don’t need to add these scripts again, since we’ve already added them. You can find them in the Custom JS field on the Settings tab:


To make it work on your website, you just need to publish changes in your widgets :slightly_smiling_face: