How can I retrieve word count from a "text area" for calculation?

  • DEENSP
    Asked on November 29, 2014 at 2:10 AM

    I need a simple form to process word count from a text area and then multiply this amount by a rate per word amount (e.g. 0.10, 0.12) so that the total amount in US Dollars can be paid via PayPal using JotForm and PayPal Standard Checkout.  Please check the online form http://form.jotform.co/form/43305638531856 and the screenshot with the required functionality.  Can this be implemented in JotForm?

    Thanks

    GM

    Jotform Thread 466451 Screenshot
  • Elton Support Team Lead
    Replied on November 29, 2014 at 7:42 AM

    Hi,

    Unfortunately, we do not have that functionality in the form builder. We only have entry limits on text areas. Example:

    How can I retrieve  word count from a text area for calculation? Image 1 Screenshot 20

    However, I'm sure you can achieve that when you use your form source code and apply custom javascript that performs the text area word count. Here's an example script that should help.

    <script>

    $('input_3').onchange = $('input_3').onkeyup = function(){

      s = $('input_3').value; 

      s = s.replace(/(^\s*)|(\s*$)/gi,"");

      s = s.replace(/[ ]{2,}/gi," ");

      s = s.replace(/\n /,"\n");

      $('input_4').value = s.split(' ').length; 

    }

    // input_3 must be your textarea field ID.

    // replace input_4 with the textbox ID you want to populate the result.

    </script>

    If you need help with the implementation of this script, let us know.

    Have a good day!

  • DEENSP
    Replied on November 29, 2014 at 1:53 PM

    Hi Elton,

    Indeed I would need help to implement this simple form.  Will it have any cost if you can implement it for me?  It would be easier if I could edit the HTML source from JotForm and not outside.  Please advice.

     

    Best regards

    GM

  • Charlie
    Replied on November 29, 2014 at 8:42 PM

    Hi,

    I'm currently making a workaround with the code that my colleague Elton has, let me just finish it and I'll get back to you if it works in my end. Although, please do take note that the changes will apply on the form's source code and you will need to embed it on your website.

    Thank you.

  • DEENSP
    Replied on November 29, 2014 at 9:21 PM
    New response receivedHi Charlie,
    Thank you for your reply on this topic. I would like to have this form working on my website. I have created another Form http://form.jotform.co/form/43321050619849 which is currently working but it is not the Form that I need for unlimited text input and calculation. I have also integrated the PayPal functionality all within JotForm and no extra coding.
    I would greatly appreciate it if you can add the word count and PayPal payment to the source code so that I can embed it on my webpage. My PayPal email is geodirect@yahoo.com
    Best regards,
    GM
    ...
  • jonathan
    Replied on November 30, 2014 at 5:09 AM

    Hi GM,

    I suggest you finalize first your jotform that you want to have unlimited text input and Paypal payment integration.

    After you have completed creating the form in your Form Builder, inform us here so that we can proceed with the custom solution needed for the word count calculation. 

    Thanks.

  • Elton Support Team Lead
    Replied on December 1, 2014 at 1:43 PM

    @DEENSP

    Here's the script for this form http://form.jotform.co/form/43321050619849. Just take the source code of this form on the from builder, append the following script to it and you're ready to embed it anywhere you want.

    <script>

    $('input_8').onchange = $('input_8').onkeyup = function(){

      s = $('input_8').value; 

      s = s.replace(/(^\s*)|(\s*$)/gi,"");

      s = s.replace(/[ ]{2,}/gi," ");

      s = s.replace(/\n /,"\n");

        $('input_16_donation').value = ((s.split(' ').length) * 0.12).toFixed(2);

    }

    </script>

    By the way, there's no need for the subtotal field as I have output the calculation result directly on the Paypal field, unless you will require it.

    It should work like the following:

    https://shots.jotform.com/elton/calculate_466451.html

    If you need further assistance, let us know. Thanks!

  • DEENSP
    Replied on December 1, 2014 at 3:21 PM
    New response receivedHi Elton,
    Thank you for the script. I will integrate it to the source code of my Form and see how it works. I will tell you when it is done.
    Best regards,
    GM
    ...
  • Ben
    Replied on December 1, 2014 at 3:56 PM

    Hi,

    Great. Do let us know how it goes. :)

    Best Regards,
    Ben

  • DEENSP
    Replied on December 2, 2014 at 5:01 PM

    New response receivedHi EltonCris,
    Your scripts did not work well within my Form code. In a simple form, it does not input the calculated value in the textbox and on another form it does not direct to the PayPal checkout. I am attaching the links to the forms from my website server. Simple form to calculate word count http://www.deensp.com/desquicktrans2.html and the other with PayPal integration http://www.deensp.com/desquicktrans3.html No word count data is added in the textbox upon submission. I am also attaching the files with the codes. Please check them out and tell what is not in place.
    Regards,
    GM
    ...

  • Elton Support Team Lead
    Replied on December 3, 2014 at 9:41 AM

    @DEENSP

    Place the script right after the ending form tag </form>, that should correct it.

    Thanks!

  • DEENSP
    Replied on December 3, 2014 at 5:12 PM

    HI,

    I have added the script in the specified place and it seems to work now for my Form.  From your first code I added a new variable to calculate the word count and display below the Textarea.

    Upon pressing the Submit button it directs me to the PayPal area but I do not receive an email with the submitted data.  My question is, will it send the submitted data to my email after payment with PayPal?

    Here is the link to the Form: http://www.deensp.com/desquicktrans.html

    Best regards,

    GM

    How can I retrieve  word count from a text area for calculation? Image 1 Screenshot 20

  • Ben
    Replied on December 3, 2014 at 6:18 PM

    Hi,

    I am glad that Elton's code and suggestions worked for you.

    Now in regards to your second question, since it is not related to this thread and its issue, I have moved it to a new thread where we will be replying to you shortly.

    You can find it here: http://www.jotform.com/answers/469041.

    Best regards,
    Ben

  • Bjorn
    Replied on February 28, 2017 at 3:18 AM

    Hello Jotform

     

    I have followed the thread and tried to implement the similar thing on my form. Please see the form in below link.

     

    I want the number of words from the text area "Enter your source text" to appear in the field below "Number words in source text".

    I tried follow the advice above, but it did not work on my end.

    It would be very nice of you if you are able to advice me on how I can get it to happen.

    I also tried to "clone" the forms from your above examples to see how the form looked like, but "permission denied" was the message I got when I tried to import the form.

     

    Looking forward to hearing from you within soon.

    Best Regards,

    Bjorn

  • Beanie3556
    Replied on February 28, 2017 at 3:27 AM

    http://form.jotform.co/form/43321050619849

     

    When trying to import this form it says "unauthorized access", I do not have the authorization to get this form.

     

    If possible, could I ask you to modify the form and allow me to get access to it so that I can download the source code?

     

    Thank you very much in advance for your support.

     

    Best Regards,

    Bjorn

  • Charlie
    Replied on February 28, 2017 at 4:58 AM

    @Beanie3556

    Hi, to better assist you, I have opened a separate thread for your concern. Please refer to this link instead: https://www.jotform.com/answers/1077741. We will address it accordingly. 

    Thank you.