mardi 21 juin 2016

Adding drop-down menu and a text box when a user click on a checkbox

In my rails project I'd like to add a drop-down menu(with some options) and a textbox only if a user clicks on a checkbox. How could I create the drop-down and textbox in rails view?

    <body>
        <h2>Please check the items <br></h2>
        <% @lp_title.each do |lp_number, title| %>
                <%= check_box_tag "Check", lp_number, checked = false %>
                <%= lp_number + ": "%> <%= link_to title, @lp_image[lp_number]%><br>
                <br>
        <% end %>
        <div class="col-md-24    text-center" > 
            <%= button_to "Submit", { :action => "new" }%>
        </div>
        <script type="text/javascript">
  var checkbox = document.getElementById('product_pay_with_card');
  var details_div = document.getElementById('card_details');
  checkbox.onchange = function() {
     if(this.checked) {
       details_div.style['display'] = 'block';
     } else {
       details_div.style['display'] = 'none';
     }
  };
</script>
    </body>
</html>




Aucun commentaire:

Enregistrer un commentaire