Sign in to follow this  
frnd

O Script, Mesmo Com Erro, Envia Os Dados

Recommended Posts

ele parece estar funcionando, mas quando um campo está incorreto, ele insere mesmo assim, porque será?

<script language="javascript"> 
  

function validaCPF() {
                 cpf = document.form1.cpf.value;
                 erro = new String;
                 if (cpf.length < 11) erro += "são necessarios 11 digitos para verificacao do CPF! "; 
                 var nonNumbers = /\D/;
                 if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! "; 
                 if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
                        erro += "Numero de CPF invalido!"
               }
               var a = [];
               var b = new Number;
               var c = 11;
               for (i=0; i<11; i++){
                       a[i] = cpf.charAt(i);
                       if (i < 9) b += (a[i] * --c);
               }
               if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
               b = 0;
               c = 11;
               for (y=0; y<10; y++) b += (a[y] * c--); 
               if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
               if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
                          if (erro.length == 0)
                           erro +="Digito verificador com problema! O correto seria "+a[9]+""+a[10];
               }
               if (erro.length > 0){
                       alert(erro);
                       return false;
               }
               alert("O número do CPF verificado está correto. Ou seja, os dígitos verificadores conferem com o número básico. " +
"Tal verificação, porém, não examina se o CPF está suspenso ou cancelado pela Receita Federal. "+ 
"Para consulta do CPF junto à Receita Federal, clique no link disponível no final dessa página ");
               return false;
       }


 </script>
E no HTML,
<form name="form1" action="CadEgresso_exe.php" method="post" class="formCad2" id="formCad2">
            <table class="TabelaDadosCad">
            <tr> 
            <td class="label">ID Antigo:</td> 
              <td> <input type="text" class="campoid" name="id"></td> 
            </tr> 
             <tr> 
            <td class="label">Nome:</td> 
              <td> <input type="text" class="camponome" name="nome"></td> 
            </tr> 
            <tr> 
              <td class="label">Dt. Nasc.:</td> 
              <td><input type="text" class="campodata" name="dtnasc"></td> 
            </tr> 
            <tr>
                <td class="label">RG:</td>
                <td><input type="text" maxlength="12" class="camporg" name="rg"></td>                
            </tr>
            <tr>
                <td class="label">Estado:</td>
                <td><select name="estado" class="camposelectEstadoCidade">
                    <option value="nomeestado"> Selecione Abaixo:</option>
                    </select>                
                </td>                
            </tr>
            <tr>
                <td class="label">Cidade:</td>
                <td><select name="estado" class="camposelectEstadoCidade">
                    <option value="nomeestado"> Selecione Abaixo:</option>
                    </select></td>                
            </tr>
            <tr>
                <td class="label">Órgão Ex.:</td>
                <td><input type="text" class="campoorgaoexpeditor" name="orgaoexpeditor"></td>                
            </tr>
            <tr>
                <td class="label">CPF:</td>
                <td><input type="text" maxlength="11" class="campocpf" name="cpf"></td>            
            </tr>
            <tr>
                <td class="label">Email:</td>
                <td><input type="text" class="campoemail" name="email"></td>            
            </tr>
            <tr> 
              <td class="label">Est. Civil:</td> 
              <td><select name="ec" class="camposelectEC"> 
                  <option value="">Escolha Abaixo</option>
                  <option value="Casado">Casado
                  <option value="Solteiro">Solteiro
                  <option value="Divorciado">Divorciado
                  <option value="Amasiado">Amasiado
                  <option value="Uniao Estavel">União Estável</option>    
                </select> </td> 
            </tr>  
            <tr> 
              <td class="label">Username:</td> 
              <td><input type="text" class="campousername" name="usuario"> </td> 
            </tr> 
            <tr> 
              <td class="label">Senha:</td> 
              <td><input type="password" class="camposenha" name="senha"></td> 
            </tr>
            <tr> 
              <td colspan="2"><br> 
                <input type="submit" name="cadastrar" value="" class="btnCad" onClick="validaCPF()"> 
                <input type="submit" name="alterar" value="" class="btnAlterar">
                <input type="reset" name="limpar" value="" class="btnLimpar"> </td> 
            </tr> 
            </table>

Share this post


Link to post
Share on other sites

Insere assim mesmo porque a validação não pega no dado, sendo assim é sub-entendido que passou pela validação e que esta tudo ok.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this