2 Replies Latest reply on Jul 16, 2006 2:35 PM by Guillermo1009

    capitalised first letter

    macca242424 Level 1
      Hi i have a form which is passed to this insert query below, i need the first letters of firstname and surname to be capitalised if they are not in the form, is this possible?

      <cfquery name="Insert datasource="Users">
      INSERT INTO TempUsers
      (Name, firstName, Surname, EmailAddress, Password)
      VALUES
      ('#form.FirstName#', '#form.Surname#', '#form.EmailAddress#', '#form.password#')
      </cfquery>
        • 1. capitalised first letter
          Dan Bracuk Level 5
          NewWord = ucase(left(OldWord, 1)) & right(OldWord, len(OldWord) -1);
          • 2. Re: capitalised first letter
            Guillermo1009
            Place this function in say the top of the page then use the function anywhere in the page. You could also create it in the request scope and use it just there or make it permament. Your choice.

            <!------------------------------------------------------------------>
            <!--- Return string with initial letter capitalized. --->
            <!------------------------------------------------------------------>
            <cfscript>
            function capitalizeFirstLetter(word) {
            return UCase(Mid(word,1, 1)) & LCase(mid(word, 2, len(word)));
            }
            </cfscript>

            <cfquery name="Insert datasource="Users">
            INSERT INTO TempUsers
            (Name, firstName, Surname, EmailAddress, Password)
            VALUES
            ('#capitalizeFirstLetter(form.FirstName#)', '#capitalizeFirstLetter(form.Surname)#', '#form.EmailAddress#', '#form.password#')
            </cfquery>