0
I went to try to ride a script to verify the status in which the CPF was issued. However, I am unable to use the substring
, it returns me the following error:
Uncaught Typeerror: Cannot read Property 'substring' of null
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script>
function verificar(){
var cpf = document.getElementById(cpf);
if(cpf.substring(7,9) == "0"){
alert("Rio Grande do Sul");
}
else if(cpf.substring(7,9) == "1"){
alert(" Distrito Federal – Goiás – Mato Grosso – Mato Grosso do Sul – Tocantins ");
}
else if(cpf.substring(7,9) == "2"){
alert(" Pará – Amazonas – Acre – Amapá – Rondônia – Roraima");
}
else if(cpf.substring(7,9) == "3"){
alert(" Ceará – Maranhão – Piauí");
}
else if(cpf.substring(7,9) == "4"){
alert(" Pernambuco – Rio Grande do Norte – Paraíba – Alagoas ");
}
else if(cpf.substring(7,9) == "5"){
alert(" Bahia – Sergipe ");
}
else if(cpf.substring(7,9) == "6"){
alert("Minas Gerais ");
}
else if(cpf.substring(7,9) == "7"){
alert("Rio de Janeiro – Espírito Santo");
}
else if(cpf.substring(7,9) == "8"){
alert("São Paulo");
}
else if(cpf.substring(7,9) == "9"){
alert("Paraná – Santa Catarina");
}
}
</script>
<title>CPF</title>
</head>
<body>
<p>Informar CPF</p><input type="text" id="cpf">
<input type="button" id="opcao" name="opcao" value="Verificar" onclick="verificar()"><br>
</body>
</html>