Query on counting characters
Last Post 04-23-2013 05:13 AM by Ryan Bakerink. 3 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
markevnzUser is Offline
skipping stones
skipping stones
Posts:6
Avatar

--
04-22-2013 02:47 AM
    Hi,
    We would like to be able to charge the customer a fixed amount per character (as entered in a textfield), the number of which is successfully defined from using your Demo 6 showcasing the number of characters.
    Is it possible to use the 'totalLen' variable and assign it to a $ShortField name field so that I can calculate a total cost based on a per character price?
    Do you have any suggestions as to any methods of how I can go about achieving this. My javascript knowledge is so-so and I'm definately not a master at it so any advice or examples would of great help.
    Thanks
    Ryan BakerinkUser is Offline
    river guide
    river guide
    Posts:1900
    Avatar

    --
    04-22-2013 05:25 AM
    Hello Mark,

    You can use Token's within your JavaScript calculations inside of Dynamic Forms. Please note that the ShortFieldNames that you provide for each DF Question will become an available token that you can use.

    I would encourage you to plan out the logic needed for this calculation, simply write down the requirements so that the logic can come easily.

    I would start by creating a variable that stores the length of the field that you're charging based on the number of characters provided. This script will be somewhat of like a ranging/tiered calculation.

    ------------------------------------------------------------------------------------------------------
    var TotalCharacters = $(TokenName);
    var TotalPrice = 0.00;

    if(TotalCharacters.length > 0 && TotalCharacters.length < 100)
    {
    TotalPrice = 10.00;
    }

    else if(TotalCharacters.length > 100 && TotalCharacters.length < 200)
    {
    TotalPrice = 15.00;
    }

    etc.....

    //At the end you can assign the TotalPrice to a DF Question:

    $(HiddenValue) = TotalPrice;
    ------------------------------------------------------------------------------------------------------

    By assigning TotalPrice to a DF Question, this enables you to use this value in Form Completion Events as well as Payment Gateways.

    I hope this helps you out. Let us know if you have any questions.

    Thanks,

    Ryan

    markevnzUser is Offline
    skipping stones
    skipping stones
    Posts:6
    Avatar

    --
    04-23-2013 01:23 AM

    Hi Ryan,
    Your advice and code example worked great. I have noticed though that the character count starts at 2 when the very first one is entered (it does this on your Demo 6 example also). Why is it doing this and how can I rectify it please?

    Also, the count is including the spaces. Is there a way of ignoring the spaces as we charge the user per character and it seems a little unfair to charge for an empty space! (I'm using the 'onkeypress' method of capture, if that makes any difference?)

    Thanks 

    Ryan BakerinkUser is Offline
    river guide
    river guide
    Posts:1900
    Avatar

    --
    04-23-2013 05:13 AM
    Hello Mark,

    I believe the countChars() JavaScript function is off a little. I would recommend going out on the web to find a more suitable JavaScript function. After all, you're not locked in to having to use only this function.

    This is a great forum that you can reference:
    http://www.webdeveloper.com/forum/s...nus-spaces

    I would recommend researching for what you're looking for. A simple Google search will bring back resources that will assist you. Try to search using "javascript count characters no spaces".

    I have provided the logic to assist you with this, now you just need to factor in all of your requirements and build the script you need. If you need additional assistance, you can always enlist for assistance with Data Springs.

    Let me know if you have any questions.

    Thanks,

    Ryan


    ---
  • film izle
  • 720 izle
  • film
  • sinema izle
  • film makinesi
  • T�rk�e dublaj film
  • film izle
  • film izle
  • baglan film izle
  • sinema izle
  • 1080 film izle
  • film mercegi