2013-07-12 36 views
0

這是我檢查,如果字段是真的還是假的如何激活註冊按鈕後,所有信息均真實

function textoEnP(){ 
var idInput2 = $(this).attr("id"); 

switch(idInput2){ 
    case "nombre": 
    { 
     if($(this).val() == ""){ 
      $(".texto_req_reg").html("No puede estar vacio"); 
      $(".texto_req_reg").css("color", "#C60"); 
      nombreValido = false; 
     }else{ 
      $(".texto_req_reg").html("Correcto"); 
      $(".texto_req_reg").css("color", "#990"); 
      nombreValido = true; 
     } 
    break; 
    } 
    case "apellido": 
    { 
     if($(this).val() == ""){ 
      $(".texto_req_reg").html("No puede estar vacio"); 
      $(".texto_req_reg").css("color", "#C60"); 
      apellidoValido = false; 
     }else{ 
      $(".texto_req_reg").html("Correcto"); 
      $(".texto_req_reg").css("color", "#990"); 
      apellidoValido = true; 
     } 
    break; 
    } 
    case "edad": 
    { 
     if(isNaN($(this).val())){ 
      $(".texto_req_reg").html("Debe ingresar solo numeros"); 
      $(".texto_req_reg").css("color", "#C60"); 
      edadValida = false; 
     }else if($(this).val() == ""){ 
      $(".texto_req_reg").html("No puede estar vacio"); 
      $(".texto_req_reg").css("color", "#C60"); 
      edadValida = false; 
     }else{ 
      $(".texto_req_reg").html("Correcto"); 
      $(".texto_req_reg").css("color", "#990"); 
      edadValida = true; 
     } 
    break; 
    } 
    case "mail": 
    { 
     if($(this).val().length < 9 && isNaN($(this).val())){ 
      $(".texto_req_reg").html("Debe usar un formato valido"); 
      $(".texto_req_reg").css("color", "#C60"); 
      mailValido = false; 
     }else if($(this).val() == ""){ 
      $(".texto_req_reg").html("No puede estar vacio"); 
      $(".texto_req_reg").css("color", "#C60"); 
      mailValido = false; 
     }else{ 
      $(".texto_req_reg").html("Correcto"); 
      $(".texto_req_reg").css("color", "#990"); 
      mailValido = true; 
     } 
    break; 
    } 
    case "contraseña": 
    { 
     password = $(this).val(); 
     if($(this).val().length < 9){ 
      $(".texto_req_reg").html("Debe tener más de 8 caracteres"); 
      $(".texto_req_reg").css("color", "#C60"); 
     }else{ 
      $(".texto_req_reg").html("Correcto"); 
      $(".texto_req_reg").css("color", "#990"); 
      contraseñaValida = true; 
     } 
    break; 
    } 
    case "repetir_contraseña": 
    { 
     if($(this).val() !== password){ 
      $(".texto_req_reg").html("Debe coincidir con su contraseña"); 
      $(".texto_req_reg").css("color", "#C60"); 
     }else{ 
      $(".texto_req_reg").html("Correcto"); 
      $(".texto_req_reg").css("color", "#990"); 
      repContraseñaValida = true; 
     } 
    break; 
    } 
    if($("#checkbox_legales").is(":checked")){ 
    checkbox_legalesValido = true; 
}else{ 
    checkbox_legalesValido = false; 
    } 
    habilitarBoton(); 
} 

}

這是激活,如果一切註冊按鈕的功能的情況下是確定

function habilitarBoton(){ 
if(nombreValido && apellidoValido && edadValido && mailValido && contraseñaValida && repContraseñaValida && checkbox_legalesValido) 
{ 
    $("#registrarse").removeAttr("disabled").css('background-color', '#fff');; 
}else{ 
    $("#registrarse").attr("disabled", "disabled").css({'background-color' : '#ccc', 'color' : '#000'}); 
} 

}

的主要問題是對於CHEC條件kbox,不工作不知道爲什麼,我的表單將無法工作,直到我找出。有什麼建議麼?

編輯:這是HTML

<div id="cuadro_izq"> 
     <form> 
      <div class="titulo_loguearse"> 
       LOGUEARSE 
      </div> 
      <div id="form_loguearse"> 
       <div class="renglon"> 
        <label for="tex1" class="loguin_label">Mail:</label> 
        <INPUT type="text" NAME="mail" id="tex1" class="loguin_field"><br /> 
       </div> 
       <div class="renglon"> 
        <label for="tex2" class="loguin_label">Contraseña:</label> 
        <INPUT TYPE="password" NAME="contrasena" id="tex2" class="loguin_field"> 
       </div> 
      </div> 
      <div id="boton_loguin"> 
       <input type="submit" value="Entrar" id="entrar" /> 
      </div> 
     </form> 
    </div> 
    <div id="cuadro_der"> 
     <form> 
      <div class="titulo_loguearse"> 
       REGISTRARSE 
      </div> 
      <div id="form_registro"> 
       <div class="renglon"> 
        <label for="tex3" class="loguin_label">Nombre:</label> 
        <INPUT type="text" NAME="nombre" id="nombre" class="registro_field"><br /> 
        <div id="caja_req_reg_nom"> 
        </div> 
       </div> 
       <div class="renglon"> 
        <label for="tex4" class="loguin_label">Apellido:</label> 
        <INPUT TYPE="text" NAME="apellido" id="apellido" class="registro_field"><br /> 
        <div id="caja_req_reg_ape"> 
        </div> 
       </div> 
       <div class="renglon"> 
        <label for="tex5" class="loguin_label">Edad:</label> 
        <INPUT type="text" NAME="edad" id="edad" class="registro_field"><br /> 
        <div id="caja_req_reg_edad"> 
        </div> 
       </div> 
       <div class="renglon"> 
        <label for="tex6" class="loguin_label">Mail:</label> 
        <INPUT TYPE="text" NAME="mail" id="mail" class="registro_field"><br /> 
        <div id="caja_req_reg_mail"> 
        </div> 
       </div> 
       <div class="renglon"> 
        <label for="tex7" class="loguin_label">Contraseña:</label> 
        <INPUT type="password" NAME="contraseña" id="contraseña" class="registro_field"><br /> 
        <div id="caja_req_reg_pass"> 
        </div> 
       </div> 
       <div class="renglon"> 
        <label for="tex8" class="loguin_label">Repetir contraseña:</label> 
        <INPUT TYPE="password" NAME="repetir_contraseña" id="repetir_contraseña" class="registro_field"><br /> 
        <div id="caja_req_reg_repass"> 
         <!--<p class="texto_req_reg">Texto prueba</p>--> 
        </div> 
       </div> 
       <div class="renglon" id="renglon_legales"> 
        <INPUT TYPE="checkbox" NAME="aceptar_legal" id="checkbox_legales"> 
        <label for="tex9" id="legales_label">Acepto las disposiciones legales</label><br /> 
       </div> 
      </div> 
      <div id="boton_registrarse"> 
       <input type="submit" value="Registrarse" id="registrarse" disabled="disabled" /> 
      </div> 
     </form> 
    </div> 
+0

你能告訴你的HTML –

+0

哪裏是'textoEnP ()'叫? – rednaw

+0

textoEnP()在document.ready中像這樣調用$(「.registro_field」)。keyup(textoEnP); – maurilop

回答

0
idInput2 

僅匹配1 case,所以沒有達到所有其他條件。 所以,如果你調用該函數一次,只有你驗證的人得到真正的,如果你把它的每一個驗證你可能希望將呼叫轉移到habilitarBoton()了該功能的

+0

這是一個問題,'habilitarBoton()'沒有被調用,所以驗證不會發生。我應該在哪裏調用該功能? – maurilop

+0

我想你不應該在這裏使用'switch-case'。使用'if( ==「」){'...對於您的所有驗證。 – MMMagic