Avoid sending form if I have selected radiobuttons

0

I'm doing an embed code for a mailchimp form I have 4 options OP 1,2,3 and 4

Each one has 2 radiobuttons YES and NO how do I make the form not be sent if ALL RADIOBUTTONS ARE IN 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>

Thank you very much

    
asked by Rickzize 18.11.2017 в 01:22
source

2 answers

0

Try this! I hope I serve you.

    <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>
    
answered by 18.11.2017 в 04:30
0

with jquery you could do this

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

}

before sending the form you have this conditional

if(validar()){
  enviar...
} else {
 No enviar ...
}
    
answered by 23.11.2017 в 03:38