<link rel="stylesheet" type="text/javascript" href="js/intranet.js">
/* função em JavaScript para validar a informação */
function validacao(elem)
{
if (elem.nome.value == "")
{
alert ("O campo Nome encontra-se por preencher");
elem.nome.focus();
return false;
}
if (elem.morada.value == "")
{
alert ("O campo Morada encontra-se por preencher");
elem.morada.focus();
return false;
}
if (elem.codpostal.value.length != 8)
{
alert(" O formato correcto é do codigo postal é nnnn-nnn");
elem.codpostal.focus();
return false;
}
if (elem.localidade.value == "")
{
alert("Deve inserir a sua localidade");
elem.localidade.focus();
return false;
}
if ( (elem.telefone.value != 0) && (elem.telefone.value.length != 9))
{
alert("O campo telefone deve ter 9 dígitos ou ser deixado a 0");
elem.telefone.focus();
return false;
}
if (elem.telemovel.value.length != 9)
{
alert("O campo telemóvel deve ter 9 dígitos");
elem.telemovel.focus();
return false;
}
if (elem.naturalidade.value == "")
{
alert("O campo Naturalidade encontra-se por preencher");
elem.naturalidade.focus();
return false;
}
if (elem.data_nasc.value.length != 10)
{
alert ("Preencha a data de nascimento no formato dd-mm-aaaa");
elem.data_nasc.focus();
return false;
}
if ((elem.bi.value.length < 7) || (elem.bi.value.length > 8))
{
alert ("Confira o número do BI, tem de ter 7 ou 8 dígitos");
elem.bi.focus();
return false;
}
if (elem.arquivo.value == "")
{
alert("Insira o arquivo de identificação");
elem.arquivo.focus();
return false;
}
if (elem.data_emissao.value.length != 10)
{
alert ("Preencha a data de emissão do BI no formato dd-mm-aaaa");
elem.data_emissao.focus();
return false;
}
if (elem.ncont.value.length != 9)
{
alert ("O número de contribuinte tem de ter 9 números");
elem.ncont.focus();
return false;
}
if (elem.curso.value == "se" )
{
alert ("Deve escolher um curso");
elem.curso.focus();
return false;
}
opcao_hab_lit = false;
for ( i = 0; i < elem.hablit.length; i++)
{
if (elem.hablit[i].checked == true)
{
elem.opcao_hab_lit = true;
}
}
if ( (elem.opcao_hab_lit == true ) && (elem.nota_qmc.value == "nf") )
{
alert ("Tem de escolher uma opção, na nota de Química");
elem.nota_qmc.focus();
return false;
}
if ( (elem.opcao_hab_lit == true ) && (elem.nota_inf.value == "nf") )
{
alert("Tem de escolher uma opção, na nota de Informática");
elem.nota_inf.focus();
return false;
}
if ( (elem.opcao_hab_lit == true ) && (elem.nota_cfq.value == "nf") )
{
alert("Tem de escolher uma opção, na nota de Ciências Fisico-Quimícas");
elem.nota_cfq.focus();
return false;
}
if ( (elem.opcao_hab_lit == true ) && (elem.nota_fis.value == "nf") )
{
alert("Tem de escolher uma opção, na nota de Física");
elem.nota_fis.focus();
return false;
}
if ( (elem.opcao_hab_lit == true ) && (elem.nota_prt.value == "nf") )
{
alert("Tem de escolher uma opção, na nota de Português");
elem.nota_prt.focus();
return false;
}
if ( (elem.opcao_hab_lit == true ) && (elem.nota_mat.value == "nf") )
{
alert("Tem de escolher uma opção, na nota de Matemática");
elem.nota_mat.focus();
return false;
}
if ( (elem.opcao_hab_lit == true ) && (elem.disc_falta.value != "") )
{
alert("Só deve preencher este campo caso não tenha acabado o 12º ano ou um curso profissional");
return false;
}
if ( (elem.opcao_hab_lit == false ) && (elem.disc_falta.value == "") )
{
alert("Deve preencher OU o campo da escolaridade OU o das disciplinas em atraso");
return false;
}
opcao_sit_prof = false;
for ( i = 0; i < elem.sit_prof.length; i++)
{
if (elem.sit_prof[i].checked == true)
{
opcao_sit_prof = true;
}
}
if (opcao_sit_prof == false )
{
alert("Tem de nos informar relativamente à sua situação profissional");
elem.sit_prof.focus();
return false;
}
<form action="inscrever.php" method="post" name="inscricao" class="style1" id="formulario" onSubmit="return validacao(this)">
<link rel="stylesheet" type="javascript" href="validar.js">
/* função em JavaScript para validar a informação */
function validar(elem)
{
if (elem.local.value == "")
{
alert("Deve inserir a sua localidade");
elem.local.focus();
return false;
}
}
<form method="post" action="enviar.php" id="addnovo" onSubmit="return validar(this)" name="addnovo">
Código:<link rel="stylesheet" type="javascript" href="validar.js">
<script type="text/javascript" src="validar.js"></script>