In IE7 and IE6 the form validation returns alert('Please fill the indicated fields.');
and no field is highlighted as invalid .
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="SHORTCUT ICON" href=""/>
<meta name="Author" content=""/>
<meta name="copyright" content=""/>
<title>Title test</title>
</head>
<body>
<form method="post" action="../envia/pt" name="frm" id="frm" onsubmit="return validarForm();">
<div class="campoFormulario nomeDeCampo texto textocinzaescuro" >Name<font style="color:#EE3063;">*</font></div>
<div class="campoFormulario inputDeCampo" ><input class="texto textocinzaescuro" size="31" name="nome" id="nome" value=""/></div>
<div class="campoFormulario nomeDeCampo texto textocinzaescuro" >Company<font style="color:#EE3063;">*</font></div>
<div class="campoFormulario inputDeCampo" ><input class="texto textocinzaescuro" size="31" name="Empresa" id="Empresa" value=""/></div>
<div class="campoFormulario nomeDeCampo texto textocinzaescuro" >Funtion</div>
<div class="campoFormulario inputDeCampo" ><input class="texto textocinzaescuro" size="31" name="Cargo" id="Cargo" value=""/></div>
<div class="campoFormulario nomeDeCampo texto textocinzaescuro" >Email<font style="color:#EE3063;">*</font></div>
<div class="campoFormulario inputDeCampo" ><input class="texto textocinzaescuro" size="31" name="Email" id="Email" value=""/></div>
<div class="campoFormulario nomeDeCampo texto textocinzaescuro" >Telephone</div>
<div class="campoFormulario inputDeCampo" ><input class="texto textocinzaescuro" size="31" name="Telefone" id="Telefone" value=""/></div>
<div class="campoFormulario nomeDeCampo texto textocinzaescuro" >Subject<font style="color:#EE3063;">*</font></div>
<div class="campoFormulario inputDeCampo" ><textarea class="texto textocinzaescuro" name="Assunto" id="Assunto" rows="2" cols="28"></textarea></div>
<div class="campoFormulario nomeDeCampo texto textocinzaescuro" > </div>
<div class="campoFormulario inputDeCampo" style="text-align:right;" ><input id="Cbutton" class="texto textocinzaescuro" type="submit" name="submit" value="Send" /></div>
<?php echo form_close(); ?>
<script type="text/javascript">
function validarForm(){
var error = 0;
if(!validateNome(document.getElementById("nome"))){ error = 1 ;}
if(!validateNome(document.getElementById("Empresa"))){ error = 1 ;}
if(!validateEmail(document.getElementById("Email"))){ error = 1 ;}
if(!validateNome(document.getElementById("Assunto"))){ error = 1 ;}
if(error == 0){
return true;
}else{
alert('Please fill the indicated fields.');
return false;
}
}
function validateNome(fld){
if( fld.value.length == 0 ){
fld.style.backgroundColor = '#FFFFCC';
//alert('Descrição é um campo obrigatório.');
return false;
}else {
fld.style.background = 'White';
return true;
}
}
function trim(s)
{
return s.replace(/^\s+|\s+$/, '');
}
function validateEmail(fld) {
var tfld = trim(fld.value);
var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
if (fld.value == "") {
fld.style.background = '#FFFFCC';
//alert('Email é um campo obrigatório.');
return false;
} else if (!emailFilter.test(tfld)) {
//alert('Email inválido.');
fld.style.background = '#FFFFCC';
return false;
} else if (fld.value.match(illegalChars)) {
fld.style.background = '#FFFFCC';
//alert('Email inválido.');
return false;
} else {
fld.style.background = 'White';
return true;
}
}
</script>
</body>
</html>