0

estoy haciendo un embed code para un formulario de mailchimp tengo 4 opciones OP 1,2,3 y 4

Cada una tiene 2 radiobuttons SI y NO como hago para que el formulario no se envie si TODOS LOS RADIOBUTTONS ESTAN EN NO

  <input type="radio" value="Si" name="MMERGE4" id="mce-MMERGE4-0" checked> <label for="mce-MMERGE4-0">Si</label>
 <input type="radio" value="No" name="MMERGE4" id="mce-MMERGE4-1"> 
                        <label for="mce-MMERGE4-1">No</label>

Muchas gracias

2
  • ¿Qué has intentado? Y también, ¿que no se envíe si TODOS los radiobuttons están en no?¿o que no se envíe si alguno de ellos está en no?
    – Alvaro Montoro
    el 18 nov. 2017 a las 1:19
  • Hay más código que ese? Podrías poner tu código completo para analizarlo mejor. Puedes usar javascript para esa validación o usa required, pero como te digo, con algo más de código podría ayudarte mejor. el 18 nov. 2017 a las 3:02

2 respuestas 2

0

Intenta esto! espero te sirva

    <script src="http://code.jquery.com/jquery-1.7.2.min.js"/>
<body>
    <form method="POST" action="" id="id_form">
        <div>
            <label>UNO</label><br>
            <input type="radio" value="Si" name="MMERGE4" id="1-mce-MMERGE4-0"/> 
            <label for="mce-MMERGE4-0">Si</label>
            <input type="radio" value="No" name="MMERGE4" id="1-mce-MMERGE4-1"/> 
            <label for="mce-MMERGE4-1">No</label>
        </div>
        <div>
            <label>DOS</label><br>
            <input type="radio" value="Si" name="MMERGE4" id="2-mce-MMERGE4-0"> 
            <label for="mce-MMERGE4-0">Si</label>
            <input type="radio" value="No" name="MMERGE4" id="2-mce-MMERGE4-1"/>
            <label for="mce-MMERGE4-1">No</label>
        </div>
        <div>
            <label>TRES</label><br>
            <input type="radio" value="Si" name="MMERGE4" id="3-mce-MMERGE4-0"> 
            <label for="mce-MMERGE4-0">Si</label>
            <input type="radio" value="No" name="MMERGE4" id="3-mce-MMERGE4-1"/> 
            <label for="mce-MMERGE4-1">No</label>
        </div>
        <div>
            <label>CUATRO</label><br>
            <input type="radio" value="Si" name="MMERGE4" id="4-mce-MMERGE4-0"> 
            <label for="mce-MMERGE4-0">Si</label>
            <input type="radio" value="No" name="MMERGE4" id="4-mce-MMERGE4-1"/>
            <label for="mce-MMERGE4-1">No</label>
        </div>
        <div>
            <input type="submit" value="Ejecutar" name="btn" id="btn"> 
        </div>
    </form>
    <script>
        $("#id_form").on('submit', function (evt) {

            if (!$("#1-mce-MMERGE4-0").is(':checked') && 
!$("#2-mce-MMERGE4-0").is(':checked') && !$("#3-mce-MMERGE4-0").is(':checked') && !$("#4-mce-MMERGE4-0").is(':checked')) {
                evt.preventDefault();
                alert('No has marcado un Sí');
            }
        });
    </script>
</body>
0

con jquery podrias hacer esto

function validar(){
 var valida = true
 $("#contenedor-radius").find("input[type='radio']").each(function(){
 if($(this).val()=='no'){
  valida=false
 }
})
 return valida

}

antes de enviar el formulario has este condicional

if(validar()){
  enviar...
} else {
 No enviar ...
}

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.