Inline validation for cpf

Hi Experts,
I am trying to validate the CPF number ( brazilian id number, equivalent to ssn for USA). I am able to do that but I am trying to give an inline error message for correct and incorrect cpf number that the user entered.Recently, I am using "alert" for displaying message but I really want to get inline message instead of poping up dialog box for message. Any suggestions and help are really appreciated. Here is the code I had been working on.

<!-- begin snippet: js hide: false -->

<!-- language: lang-js -->

    <script language="javascript">
      function VerificaCPF () {
        if (vercpf(document.frmcpf.cpf.value))
          {document.frmcpf.submit();}else
          {errors="1";if (errors) alert('CPF NAO VALIDO');
          document.retorno = (errors == '');}}
        function vercpf (cpf)
          {if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
          return false;
          add = 0;
      for (i=0; i < 9; i ++)
        add += parseInt(cpf.charAt(i)) * (10 - i);
        rev = 11 - (add % 11);
      if (rev == 10 || rev == 11)
        rev = 0;
      if (rev != parseInt(cpf.charAt(9)))
       return false;
        add = 0;
      for (i = 0; i < 10; i ++)
        add += parseInt(cpf.charAt(i)) * (11 - i);
        rev = 11 - (add % 11);
      if (rev == 10 || rev == 11)
        rev = 0;
      if (rev != parseInt(cpf.charAt(10)))
        return false;
      alert('O CPF INFORMADO E VALIDO.');return true;}
    </script>

<!-- language: lang-html -->

    <html>
    <title> Validation</title>
    <head>
    </head>
    <body>
      <form name="frmcpf" method="post" action="default.html" onsubmit="VerificaCPF();">
      <table width="34%" border="1" cellspacing="0" cellpadding="0" align="center" height="51">
      <tr>
      <td>
      <div align="center">CPF: <br />
        <input type="text" name="cpf" size="12" maxlength="11"> <br /> <br />
        <input type="button" name="Submit" value="Checar" onclick="VerificaCPF();">
      </div>
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>

<!-- end snippet -->

`enter code here`
Bade011Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee SavidgeCommented:
Bade011Author Commented:
@Lee: I am sorry as I'm lost in above link. I could only see expression for cpf. Is it what you are trying to show me? Actually, I already did cpf validation working. I am only worry about displaying message. I want to display messages:
 "You entered correct cpf."   ->   if cpf entered is correct and
"You entered wrong cpf."     ->   if user entered wrong cpf
Currently I am displaying these message from "alert" which will pop up dialog box. I don't like this way. I am trying to figure out if I can display message by the side of input box. I hope I clarify my problem well.
Lee SavidgeCommented:
Ahh, I see. Well, stick another <div> in there and display/hide it.

Something like this:

      <div align="center">CPF: <br />
        <input type="text" name="cpf" size="12" maxlength="11"><div id="ErrorMessage" style="display: none;">Error message text here</div> <br /> <br />
        <input type="button" name="Submit" value="Checar" onclick="VerificaCPF();">

Open in new window


Then in your javascript, do something like this when the validation fails:

document.getElementById("ErrorMessage").style.display = 'block';

Open in new window

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Bade011Author Commented:
Very well. One more question: How do I use same div for 2 messages? Thanks in advance
Lee SavidgeCommented:
Have 2 divs with different ID's. Hide both by default when the page loads and control visibility via the script.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lee SavidgeCommented:
Glad it helped :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.