views:

50

answers:

1

hi what happens is that I am making an Enrollment Form, and I have a text field where I need 2 comparisons, I assess the number of ICFES snp, and if prior to 2000 has 12 digits, and after the 2000 14 ... and I've tried and nothing ... restricts me when I'm older than 14.

function verificar(valor) {
    var letras=document.form1.snp.value;
    var long=letras.length;

    //alert(long);
    if(letras.length==2)
    {
        dp=letras;
    }
    numeros=letras.charAt(2);
    //alert (numeros);
    if(dp!="ac" && dp!="av"  ) {
        document.getElementById("materias").style.display="none";
        document.getElementById("puntaje").style.display="none";
    }
    else if (long==12 && long==14)
    {
        //alert ("el numero del icfes no es correcto"); 
        document.getElementById("materias").style.display="none";
        document.getElementById("puntaje").style.display="none";
    }
   else if(dp=="ac" || dp=="av") {
       if(long==12 && numeros!=2)
       { 
           document.getElementById("materias").style.display="none";
           document.getElementById("puntaje").style.display="block";
       }
       if(numeros==2)
       {
           if(long==14)
           { 
               document.getElementById("materias").style.display="block";
               document.getElementById("puntaje").style.display="none";
           }
       }

   }
}

You have my appreciation if you can help me.

A: 

maybe you could use modern JS (first two lines of the function):

var letraselem=document.getElementById("snp");
var letras=letraselem.value;

instead of:

var letras=document.form1.snp.value;

snp must be set as id of the desired element

dusoft