Form Calculation>>Function: add "len()" as a function to calculate the length of a field entry.

  • mschuurmans
    Asked on February 8, 2019 at 4:31 PM

    I'm evaluating form tools but have a rather specific use case (for classified ad submissions) that would require a tool that can:
    1. Show the user how many characters of text they have entered.
    2. Process a payment for $0.30 per character.

    For example, the user types in a classified ad and the system shows it contains 286 characters. The user then enters 286 into the quantity field for payment, and their credit card is charged 286 x $0.30 = $85.80 (or, even better, the system automatically transfers the 286 quantity into the payment area).

    Can JotForm do this, even with some extra scripting?

  • Jed_C
    Replied on February 8, 2019 at 6:03 PM

    There is no direct way of doing this, you'll have to download the form's source code to achieve this. If you are ok with embedding your form using form's source code, you can follow this guide https://www.jotform.com/help/104-How-to-get-the-Full-Source-Code-of-your-Form and I'll try to make a sample using JS.

    Looking forward for your response. 

  • Jed_C
    Replied on February 8, 2019 at 8:51 PM

    Here's the sample form which I downloaded and create a custom script using JS to capture the character count and charge $.30 cents per character.

    You can check it from this link http://shots.jotform.com/jed/count and charge characters.

    If you have any questions, just let us know.

  • mschuurmans
    Replied on February 11, 2019 at 8:54 AM

    Thanks so much for that example. Followup questions:

    1. Is this method compatible with your payment forms? (i.e. we'd want the 'amount to be paid' field to be used for the credit card transaction)

    2. Can payment forms be embedded using the source code method? (I'm especially thinking of credit card security. I'm assuming we'd need to put it on an HTTPS page)


    BTW, is there a way to get email notifications for new replies in this thread?

  • David JotForm Support Manager
    Replied on February 11, 2019 at 11:05 AM

    1) Passing a calculated amount to a payment field is possible, please check this guide: https://www.jotform.com/help/275-How-to-Pass-a-Calculation-to-a-Payment-Field 

    2) Yes, once you finish building your form, and integrating with your preferred payment gateway, you can use any embedding method including the Source Code.

    Open a new thread if you need anything else, we will be glad to assist you.

  • mschuurmans
    Replied on February 12, 2019 at 10:24 AM

    Just a thought...instead of relying on Javascript, might it be possible to add:

    len()

    ...as one of your calculation functions? That sure would be easy, for me and other customers who might want to calculate the length of a field entry.

  • David JotForm Support Manager
    Replied on February 12, 2019 at 11:36 AM

    I will submit a feature request to add "len()" as a function. If this gets added in the future, you will be notified via this thread if this gets implemented.

    Open a new thread if you need anything else, we will be glad to assist you.

  • mschuurmans
    Replied on February 22, 2019 at 3:06 PM

    Any update on whether this feature request was accepted?

    Thought I'd check, hoping that adding an additional math function might be a fairly trivial feature request. And without it, the workaround for us will be significant (i.e. hosting the form on our own site and using custom JS).

  • Victoria_K
    Replied on February 22, 2019 at 3:59 PM

    Yes, this feature request was accepted and forwarded to the team in charge. But, I'm afraid, we still can not promise any time frame on when this will be implemented. Once we receive an update, we will notify you here. 

    By the way, you should receive emails to your account email for replies in this thread.