Send a form after checking a checkbox in html with jquery

0

I am working with a "purchase" form in which I have, in addition to many inputs, two in particular with radios that are Cash Payment and Card Payment. When my buyer selects Pago with cash and click on Send, the confirmation template where he has the seller's data should appear (in my case). In case you press "Payment by card" you should not, when sending, this template appear but ... continue with the next validation in which to complete the data of the card ... and then if everything is ok, send it. This I am working with jquery, could you tell me what code to use?

These are my two inputs:

<input type="radio" name="confirmado" id="radio2" value="comprobar">Efectivo</input><br/>
<input type="radio" name="pago" id="radio2" value="comprobar">Con tarjeta</input>
    
asked by vanesa 26.09.2017 в 19:17
source

1 answer

0

What you can do is that when you select the radio card, it shows the additional information related to the card.

That you can do with the method click() on the 2 radios, if you select card we show the div, but hide it:

$("input[name=pago]").click(function(){
  // si es tarjeta, mostramos el div que contiene la inforamcion adicional
  if(this.id == "tarjeta"){
    $("#contenido-tarjeta").show();
  }else{
    $("#contenido-tarjeta").hide();
  }
});

$("button").click(function(){

  if(!$("input[name=pago]").is(":checked")) {
    console.log("enviar informacion del formulario");
  }
  else {
     console.log("informacion valida");
  }  
});
#contenido-tarjeta{
  display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="radio" name="pago" id="efectivo" value="comprobar">Efectivo<br/>
<input type="radio" name="pago" id="tarjeta" value="comprobar"/>Con tarjeta

<div id="contenido-tarjeta">

<div>
  Fecha vencimiento <input type="text" />
</div>

<div>
  Codigo <input type="text" />
</div>

</div>
<br>
<button>enviar</button>
    
answered by 26.09.2017 в 19:37