show rest of a form if a checkbox is ckecked in ruby on rails

前端 未结 6 1000
终归单人心
终归单人心 2020-12-16 08:58

I need to ask to my user if will pay a service with credit card...if it checked the option pay_with_card? it must show the rest of the form, that ask for other data like car

6条回答
  •  庸人自扰
    2020-12-16 09:25

    Ok my solution is this: all the code in the view, if a user check pay_with_card...(mi code is in spanish) it shows the complete form...if is not checked don´t show nothing, just the same checkbox asking for payment... thanks guys.

    function mostrar (){
    var checkbox = document.getElementById('chk_tarjeta');
    if (checkbox.checked)
    document.getElementById("card_details").style.display = "block";
    else
    document.getElementById("card_details").style.display = "none";
    
    
    

    Forma de Pago

    <%= form_for(@product) do |f| %>
    <%= f.label :paga_con_tarjeta? %>
    <%= f.check_box :paga_con_tarjeta, :id => "chk_tarjeta", :onclick => "mostrar();" %>
    <%= f.label :numero_de_tarjeta %>
    <%= f.text_field :numerotarjeta %>
    <%= f.label :codigo_de_seguridad %>
    <%= f.text_field :codigoseguridad %>

提交回复
热议问题