Auto-Capitalize Problem

Discussion in 'Javascript' started by sams@centric.net, Mar 23, 2005.

  1. Guest

    First, I'll tell you up front that I am clueless when it comes to
    Javascript. So I apologize if this question is off topic.


    I have a nice little Javascript that capitalizes each field in my form
    submissions. It looks like this:


    <cfscript>
    function CapFirst(str) {
    var result = Trim(str);
    var wordCount = ListLen(result," ");
    var ProperString = "";
    for(i=1;i LTE wordCount;i=i+1) {
    ProperString = ProperString & " " & UCase(Left(ListGetAt(result,i,"
    "),1)) & LCase(RemoveChars(ListGetAt(result,i," "),1,1));
    } ProperString = Trim(ProperString);
    return ProperString;}
    </cfscript>


    Then I display the results as follows:
    #CapFirst(Session.Customer.FirstName)#


    It works fantastic, except for some reason on my final form submission,

    if someone enters an apostrophe in the field, it wants to repeat it 8
    times. So the name "O'Brien" will look like "O''''''''brien". I can
    live with the second character being lowercase, but the repeating
    apostrophe's have to go.


    Also, the amount of apostrophes returned is dependant on the number of
    words in that field. So "Bob's and Ed's" would appear as
    "Bob''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''s
    And Ed''''''''''''''''s".


    Any ideas?? Maybe adding an "if" statement to ignore the apostrophe's??
     
    , Mar 23, 2005
    #1
    1. Advertising

  2. Joakim Braun Guest

    <> skrev i meddelandet
    news:...
    > First, I'll tell you up front that I am clueless when it comes to
    > Javascript. So I apologize if this question is off topic.
    >
    >
    > I have a nice little Javascript that capitalizes each field in my form
    > submissions. It looks like this:
    >
    >
    > <cfscript>
    > function CapFirst(str) {
    > var result = Trim(str);
    > var wordCount = ListLen(result," ");
    > var ProperString = "";
    > for(i=1;i LTE wordCount;i=i+1) {
    > ProperString = ProperString & " " & UCase(Left(ListGetAt(result,i,"
    > "),1)) & LCase(RemoveChars(ListGetAt(result,i," "),1,1));
    > } ProperString = Trim(ProperString);
    > return ProperString;}
    > </cfscript>
    >
    >
    > Then I display the results as follows:
    > #CapFirst(Session.Customer.FirstName)#


    Whatever this is, Javascript it ain't.

    --
    Joakim Braun
     
    Joakim Braun, Mar 23, 2005
    #2
    1. Advertising

  3. RobG Guest

    wrote:
    > First, I'll tell you up front that I am clueless when it comes to
    > Javascript. So I apologize if this question is off topic.
    >
    >
    > I have a nice little Javascript that capitalizes each field in my form
    > submissions. It looks like this:
    >
    >
    > <cfscript>


    I have zero experience of Cold Fusion, but if you really did
    mean JavaScript, then why not use toUpperCase()?

    <input type="text" size="20" onblur="
    this.value = this.value.toUpperCase();
    ">

    --
    Rob
     
    RobG, Mar 23, 2005
    #3
  4. RobB Guest

    wrote:
    > First, I'll tell you up front that I am clueless when it comes to
    > Javascript. So I apologize if this question is off topic.
    >
    >
    > I have a nice little Javascript that capitalizes each field in my

    form
    > submissions. It looks like this:
    >
    >
    > <cfscript>
    > function CapFirst(str) {
    > var result = Trim(str);
    > var wordCount = ListLen(result," ");
    > var ProperString = "";
    > for(i=1;i LTE wordCount;i=i+1) {
    > ProperString = ProperString & " " & UCase(Left(ListGetAt(result,i,"
    > "),1)) & LCase(RemoveChars(ListGetAt(result,i," "),1,1));
    > } ProperString = Trim(ProperString);
    > return ProperString;}
    > </cfscript>
    >
    >
    > Then I display the results as follows:
    > #CapFirst(Session.Customer.FirstName)#
    >
    >
    > It works fantastic, except for some reason on my final form

    submission,
    >
    > if someone enters an apostrophe in the field, it wants to repeat it 8
    > times. So the name "O'Brien" will look like "O''''''''brien". I can
    > live with the second character being lowercase, but the repeating
    > apostrophe's have to go.
    >
    >
    > Also, the amount of apostrophes returned is dependant on the number

    of
    > words in that field. So "Bob's and Ed's" would appear as
    > "Bob''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''s
    > And Ed''''''''''''''''s".
    >
    >
    > Any ideas?? Maybe adding an "if" statement to ignore the

    apostrophe's??

    <style type="text/css">

    input.cap {
    text-transform: capitalize;
    }

    </style>
    ..............
    <input class="cap"..../>

    http://www.blooberry.com/indexdot/css/properties/text/texttrans.htm
     
    RobB, Mar 24, 2005
    #4
  5. JRS: In article <>
    , dated Wed, 23 Mar 2005 10:42:13, seen in news:comp.lang.javascript,
    posted :
    >First, I'll tell you up front that I am clueless when it comes to
    >Javascript.


    Plausible.

    >I have a nice little Javascript

    ???
    > that capitalizes each field in my form
    >submissions.


    S in, T out.

    for (T="", j=0, Sep = true ; j<S.length ; j++) {
    C = S.charCodeAt(j)
    if (Sep && C>96 && C<123) C -= 32 //1
    Sep = C<33 || C==39 || C==45 //2
    T += String.fromCharCode(C)
    }

    Follow the //1 line with lines treating lower-case letters outside the
    range a..z - for example àáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ (which you may
    not see correctly); there are many more.

    Modify the //2 line for the characters after which a letter should be
    capital.

    Note that capitalisation of "cat's-meat potter-pirbright", "duke of
    wessex" "macallen" "machinery" "o'sidney" "aesop's fables" will hive you
    problems.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr John Stockton, Mar 24, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jay
    Replies:
    1
    Views:
    19,153
    Marc Dzaebel
    Feb 25, 2004
  2. Curtis
    Replies:
    7
    Views:
    1,076
    Curtis
    Jan 6, 2006
  3. Rick
    Replies:
    6
    Views:
    6,271
    sunshine82
    Nov 11, 2007
  4. linkswanted
    Replies:
    1
    Views:
    970
  5. bob

    capitalize problem

    bob, Sep 8, 2011, in forum: Java
    Replies:
    4
    Views:
    334
    Roedy Green
    Sep 8, 2011
Loading...

Share This Page