How do I get the integer value from a textfield

Currently one of my integer text fields is of type integer but the .value returns a string.

This quite problematic as we’d like to generate promo codes but need prices to be sent as integers to the server… how can I retrieve the integer value from text fields?

Hi Ish, you can call the built in JavaScript function parseInt() like {{parseInt(textinput1.value)}} to retrieve the integer value from a string– but this might not be sufficient if you want to handle all the edge cases.

The easiest solution would be calling Lodash’s _.toNumber() function, which has a lot of these checks built in:

Hope that’s helpful!

1 Like

To expand on this, it’s definitely a bit confusing of a behavior. I think that textinput.value properties will always be strings as it is a consistent case to work with, whereas JS Number types aren’t always consistent with bigint, float, or other db numerical types which could be misleading

Awesome. Thanks, parseInt worked perfectly!

1 Like