Normalize Their Names In A Web-Form

When people input their names the data goes in the same format to the Data Base, and I have to correct each time manually.

I will explain you what I would like with examples:
  If the name input is: “RAUL”, I need it transformed to: “Raul”
  If the name input is: “RAúL”, I need it transformed to: “Raúl”
  If the name input is: “raúl”, I need it transformed to: “Raúl”
  If the name input is: “rAUl”, I need it transformed to: “Raul”
  If the name input is: “raUL”, I need it transformed to: “Raul”

… from correspondence

Some of autoresponders can capitalize the first letter of names, another can’t. You can force this with any autoresponder and opt-in / squeeze forms.

This simple JavaScript code allows you to normalize the format of names before your web-form is sent to a server.

How it works

1) Insert this code above the </head> tag of your web-page:

<script type="text/javascript">
<!--
function normalizeNames(theForm) {
 if (theForm && arguments.length > 1) {
  for (var field = 1; arguments.length > field; ++field) {
   var fieldName = arguments[field];
   if (theForm[fieldName]) {
    var names = theForm[fieldName].value.split(" ");
    for (var i = 0; names.length > i; ++i) {
     var str = names[i];
     names[i] = str.charAt(0).toLocaleUpperCase()
      + str.substr(1).toLocaleLowerCase();
    }
    theForm[fieldName].value = names.join(" ");
   }
  }
 }
}
//-->
</script>

2) Now you can use the normalizeNames( ) function with any web-form at this page with the onSubmit - attribute.
  Use the this “magic”-word as the first argument of the function.
This argument allows the function works with the specified form.
  Place the form-field names as the other attributes of the function. This allows you to use the function with various forms. Please take a look at the samples below:

...
<form action="http://www.aweber.com/scripts/addlead.pl"
method="post" onsubmit="normalizeNames(this,'name')">
Name: <input name="name" >
Email: <input name="from" >
...
</form>
 
...
<form action="optin.php" method="post"
onsubmit="normalizeNames(this,'first_name','last_name')">
First Name: <input name="first_name" >
Last Name: <input name="last_name" >
Email: <input name="email" >
...
</form>
...

This is a Live sample

Enter your name in any form:
Click this button to run the script:

 

by Michel Komarov, © Copyright 2006. iCoder.com

 

Share in social bookmarking:These icons link to social bookmarking sites where readers can share and discover new web pages.  digg del.icio.us BlinkList Reddit NewsVine YahooMyWeb co.mments

Related Articles:

6 Responses to “Normalize Their Names In A Web-Form”

  1. Any experts on website forms? - Copywriters Board Says:

    […] Re: Any experts on website forms? - Today, 06:57 PM Thanks for the link Judy… and thanks again Michel. I actually did some digging around and found a great JavaScript that corrects this problem as soon as you enter information on a form. Here’s a link to it… he also has a personalization script in there as well if you dig around his website… some great stuff! Really ironic… the guy’s name is Michel too (the second person I’ve ever seen with their name spelled this way). Warm regards, Stephen Davies http://copywritersinstitute.com Unlock The Power Of Persuasion Within You! […]

  2. michel Says:

    The only thing that would be better is if you could show how to:

    Make the normalization script “automatic” rather than by having to click on a button (I’m not sure what the function might be to do this… maybe onBlur?… not sure).

    This way you could have both the normalize script and personalize script work together

    Steve

    Hi Steve,

    You’re right, you can use onBlur event with input-tag. Use this.form as the first parameter instead of this.

    ...
    <form action="..." method="post"
    onsubmit="normalizeNames(this,'first_name','last_name')">
    First Name: <input name="first_name"
     onBlur="normalizeNames(this.form,'first_name')" >
    Last Name: <input name="last_name"
     onBlur="normalizeNames(this.form,'last_name')" >
    Email: <input name="email" >
    ...
    </form>
    ...

    I hope this helps.
    Michel

  3. barney Says:

    Michel,
    There is a problem here. Mind you, it is not a towering problem … except, perhaps, to those that it affects .

    My name is barney … it is not Barney, it is barney. There are personal, emotional reasons for the lower-case spelling. I don’t intend to go into them. But they are significant _to me_.

    Couple of years ago I was on a developer’s list, WDVL, I believe it was. There was another member, a young lady, name of Tyme, with a name problem. Her problem was a single name. She had legally altered her name to the single word, Tyme.

    Most entry forms insisted that she have two names at a minimum, a first and a last. She didn’t. So the form effectively forced her to lie in order for her to complete the form. That’s not relevant to the normalization script, but it is part of the same problem.

    When you normalize my name, you are no longer speaking to me. Barney is another living person. But Barney is not me, barney is me. It may seem insignificant to you, but when you change the way I spell my name, you disrespect me. I resent it. I may walk away because of it. And you lose the sale.

    I understand the need for standardization internally, perhaps for database searches, perhaps for other reasons. But even if you do use some normalized form of my name for your own purposes, store and address me by the name I gave you. If I have a single name, don’t force me to provide _what you consider to be_ a name. Use the one I give you, as I give it to you. Believe me, I’ll notice that you do so … and it will have an impact upon my decision whether to buy from you.

    (Side issue, but related: I have no title. I did not inherit a title; I have not been awarded a title. Don’t force me to use one if I do not provide one: I am not Mr. Ms. Mrs., or Miss. If you want to know my gender or marital state, ask … but give me the option of refusing to answer.

    Bottom line, normalize all you want for your internal usage, but *don’t* normalize *me*!

  4. erzwodezwo Says:

    Hello Michel! You cannot imagine how long I was searching for something like this. Thank You so much!!

  5. tbrown90 Says:

    Michel,

    What if my onSubmit code is like this: onSubmit=’return validateform_s();’
    Can I still use the Normalize name code? How would I write it?

  6. michel Says:

    Yes, tbrown90.
    You can insert the normalizeNames() before return validateform_s() like this:

    onSubmit="normalizeNames(this,'name') ; return validateform_s();"

    Or you could use the normalizeNames() function with onBlur attribute of the text-fields like in the 3-rd comment.

    Michel

Got a question?   Leave a Reply

You must be logged in to post a comment.