Trimming leading and trailing blanks
Last Post 03-15-2012 01:44 PM by Patrick Gaul. 5 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages Not Resolved
Patrick GaulUser is Offline
wading in the water
wading in the water
Posts:21
Avatar

--
03-12-2012 07:51 PM
    I'm looking for the best (and simplest) way to trim leading and trailing blank spaces from the value of a text string question, right after they have entered a value (tabbed off the field).

    I was thinking that a client side JavaScript like:

    $(LastName) = Trim($(LastName)); would do the trick... but that is not it.

    Any help appreciated!

    Thanks, Patrick
    Patrick GaulUser is Offline
    wading in the water
    wading in the water
    Posts:21
    Avatar

    --
    03-14-2012 05:43 PM
    Anybody? It would seem that this would be a very common action.
    Chad? Candace? Can't find anything about it in the documentation...
    LimnoUser is Offline
    skipping stones
    skipping stones
    Posts:5
    Avatar

    --
    03-15-2012 09:11 AM
    You need to add a trim function to the form's JavaScript section first and then use the simple syntax as you want:
    $(LastName) = trim($(LastName)); >>Advanced Field Options >>Client side event >>Put the above Javascript in the box for each Field. Case sensetive so use "trim" instead of "Trim"!
    You can put either trim function below to the Javascript section: >>Setup Module Configuration >>Advanced Coding Options (AJAX, jQuery, JavaScript, Initial SQL DataBind) >> Custom JavaScript File >> JavaScript File (Add the trim function within this section and click on Update Javascript File and then click on Update Settings function trim(stringToTrim) { return stringToTrim.replace(/^\s+|\s+$/g,""); } /* http://www.somacon.com/p355.php */ Or this one: function trim(s) { var l=0; var r=s.length -1; while(l < s.length && s[l] == ' ') { l++; } while(r > l && s[r] == ' ') { r-=1; } return s.substring(l, r+1); } /* http://doc.infosnel.nl/javascript_trim.html */
    Patrick GaulUser is Offline
    wading in the water
    wading in the water
    Posts:21
    Avatar

    --
    03-15-2012 11:53 AM
    Limno,

    Thanks for the excellent and detailed solution! I've tried both options, however, but still can't seem to make it work. I'm sure I'm missing something simple, but need to move my form forward to implementation. I will come back and try this later when I have more time.

    I really do, however, appreciate you taking the time to reply.

    - Patrick
    LimnoUser is Offline
    skipping stones
    skipping stones
    Posts:5
    Avatar

    --
    03-15-2012 01:29 PM

    You need to make sure to refresh your form page and check the HTML source to see both the trim function and clinet site code are both in place.

    I have tested on a DNN6.1.3 site and it works fine but I did need to do ctr-F5 a few times when I switched from these functions (update the javascript file). Good luck.

    Patrick GaulUser is Offline
    wading in the water
    wading in the water
    Posts:21
    Avatar

    --
    03-15-2012 01:44 PM
    Limno,

    I not sure if I have the correct expectation... once I had it set up, I entered a last name with several leading spaces, and tabbed off the control, and expected that the script would fire and the spaces would be trimmed. Is that what should happen?

    I'll follow your tips and try again.

    Thanks!



    ---
  • 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