Home Foros Foro dudas Foro de JavaScript CAMBIAR ESTILO ERROR FORMULARIO JAVASCRIPT

CAMBIAR ESTILO ERROR FORMULARIO JAVASCRIPT

  • Este debate tiene 0 respuestas, 1 mensaje y ha sido actualizado por última vez el hace 1 año por MIRIAM.
Viendo 1 entrada (de un total de 1)
  • Autor
    Entradas
  • #19554

    MIRIAM
    Participante

    <span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>Hola.</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>Tengo que validar un formulario y cuando los campos que se rellenen sean erróneos cuando envíe el formulario tienen que ponerse los campos en rojo añadiendo una clase a mi js.</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>He puesto una alerta para comprobar que la validación es correcta pero no quiero que salte una alerta sino que el campo del formulario se rellene en rojo con la clase .fondoRojo cuando el formulario sea erróneo.</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>¿Alguien me puede ayudar? ¿Cómo lo podría meter dentro de este código?</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>Estoy haciendo un curso y soy novata…</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>Mi código es el siguiente:</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>function validar() {</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>var nombre, partidas, expresion1;</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>nombre = document.getElementById(“nombreJugador”).value;</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>partidas = document.getElementById(“numPartidas”);</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>expresion1 = /[A-Za-z]{3,}/;</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>if (!expresion1.test(nombre)) {</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>alert(“eeeeeeeeeeeeeeee”);</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>return false;</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>}</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>if (partidas.value <= 0) {</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>alert(“eeeeeeeeeehhheeee”);</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>return false;</span><br style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;” /><span style=”color: #000000; font-family: open_sansregular, Arial; font-size: 12px;”>}</span>

Viendo 1 entrada (de un total de 1)
  • Debes estar registrado para responder a este debate.