validando enquete.
Ola pessoal tenho uma enquete com 2 perguntas,em cada pergunta tenho 4 radio e 1 campo text.
como fazer a varificar se ele preencheu cada pergunta ?
tentei fazer uma verificação mas não funciono
function valida(){
var Form = window.document.getElementById('FormX');
// campo radio
var Opcao = window.document.getElementsByTagName('input');
// campos texto
var txt1 = window.document.getElementById('txt1').value;
var txt2 = window.document.getElementById('txt2').value;
var Erro1 = 0;
var Cpo = 0;
Contador1 = Opcao.length;
if(txt1 =='' || txt2 ==''){
for(x=0; x<=parseInt(Contador1)-1; x++){
if (Opcao[x].type == 'radio') {
Cpo += 1;
if(Opcao[x].checked == false){
Erro1 += 1;
}
}
if(Erro1 >6){
alert("Escolha uma alternativa de cada pergunta!");
return false;
}else{
//Form.submit();
return true;
}
}
}else if(txt1=='' && txt2!=''){
document.Form.nome[0].checked == false;
document.Form.nome[1].checked == false;
document.Form.nome[2].checked == false;
document.Form.nome[3].checked == false;
alert('Responda a Pergunta 1.');
return false;
}else if(txt1!='' && txt2==''){
document.Form.t1[0].checked == false;
document.Form.t1[1].checked == false;
document.Form.t1[2].checked == false;
document.Form.t1[3].checked == false;
alert('Responda a Pergunta 2.');
return false;
}
}
como resolver ?
Discussão (4)
Carregando comentários...