1

I'm experimenting with Lightspeed / Twig / Rain and therefore I really need some help with something I'm trying to do.

So there are a few fields on a page with values product_configure_custom_2459429 and product_configure_custom_2459282. People can fill in a number in those fields and I want to have a button on which they click to see whether the total number is 18 or not.

So I have this right now:

<input style="width: 600px;" type="button" onclick="{% if 'product_configure_custom_2459282' + 'product_configure_custom_2459429' == '18' %}
          {{ 'Je hebt 18 stuks' | t }}
          {% else %}
          {{ 'Zorg dat je 18 stuks hebt' | t }}
          {% endif %}"></input>

This does what it needs to do but now I want the result of the onclick function to be visible as a text on the button. So basically I want people to click the button and then they see on the button 'Je hebt 18 stuks' (= they have selected 18 pieces) or 'Zorg dat je 18 stuks hebt'. With each click, that function should reload so that's why I tried the Onclick function.

But right now the button is empty shown. When I inspect it, I see that the onclick function works and loads correctly, but I don't seem to be able to make the result of that function appear as a text on the button.

So I really hope someone out there can help me. I'd be super grateful!

Here you see it in action: http://testshop-generationshop.webshopapp.com/bslect.html

1 Answers1

0

Try this :

onclick="this.value = +document.getElementById('product_configure_custom_2459429').value + +document.getElementById('product_configure_custom_2459282').value == 18 ? 'Je hebt 18 stuks' : 'Zorg dat je 18 stuks hebt'"
Bulent Vural
  • 2,630
  • 1
  • 13
  • 18