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

  • Profile Image
    DEENSP
    Asked on November 29, 2014 at 02: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

  • Profile Image
    EltonCris
    Answered on November 29, 2014 at 07:42 AM

    Hi,

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

    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!

  • Profile Image
    DEENSP
    Answered on November 29, 2014 at 01: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

  • Profile Image
    Charlie
    Answered on November 29, 2014 at 08: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.

  • Profile Image
    DEENSP
    Answered on November 29, 2014 at 09: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
    ...
  • Profile Image
    jonathan
    Answered on November 30, 2014 at 05: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.

  • Profile Image
    EltonCris
    Answered on December 01, 2014 at 01: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!

  • Profile Image
    DEENSP
    Answered on December 01, 2014 at 03: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
    ...
  • Profile Image
    Ben
    Answered on December 01, 2014 at 03:56 PM

    Hi,

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

    Best Regards,
    Ben

  • Profile Image
    DEENSP
    Answered on December 02, 2014 at 05: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
    ...

  • Profile Image
    EltonCris
    Answered on December 03, 2014 at 09:41 AM

    @DEENSP

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

    Thanks!

  • Profile Image
    DEENSP
    Answered on December 03, 2014 at 05: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

  • Profile Image
    Ben
    Answered on December 03, 2014 at 06: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

  • Profile Image
    Bjorn
    Answered on February 28, 2017 at 03: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.

     

    https://form.jotform.me/70581169965468

    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

  • Profile Image
    Beanie3556
    Answered on February 28, 2017 at 03: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

  • Profile Image
    Charlie
    Answered on February 28, 2017 at 04: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.