The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
String Length
Can anyone tell me how I can calculate the length of a text string that can be used in a calculated field? For example, If someone enters their name, I need to use the length of their name (number of characters), times a certain value to determine an amount. ie, "Fred" would be 4 characters * 0.50 or "Michael" would be 7 characters time 0.50. Apparently you can't just use [89].length or Length([89]).
Thanks.
October 31, 2018 at 10:25 am
The easiest way with jQuery is $('#selector').val().length
October 31, 2018 at 12:38 pm
Can you please provide an example? I assume I put this in the HTML "after" section? Then I need some code to update the calculated field?
November 2, 2018 at 9:20 am
The code would be something like this. Obviously, I can't test it because I don't have access to your site, but this should at least get you started in the right direction:
jQuery(document).ready(function ($) {
"use strict";
$("#field_xxxx").on('change', function() {
var strlen, amt;
strlen = $('#field_xxxx').val().length;
amt = strlen * .50;
$('#field2_xxxx').val( amt );
});
});
November 2, 2018 at 10:16 am
Awesome - thank you!
Counting the characters in a string seems like a pretty common feature that should really be included as part of the core code if anyone at formidable is listening.
I appreciate your help.
Discussion closed.