Skip to content

Instantly share code, notes, and snippets.

@ryancurtin
Created March 4, 2012 21:25
Show Gist options
  • Save ryancurtin/1974852 to your computer and use it in GitHub Desktop.
Save ryancurtin/1974852 to your computer and use it in GitHub Desktop.
jQuery Hiding Rows
<h3>Select the Number of Guests Before Proceeding: <label for="guests"></label></h3>
<select name="guests" id="guests" class="span1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
<script>
$(document).ready(function(){
$(":hidden").show();
$('#guests').live('change', function() {
var num_guests = $(this).val();
$("td[data-num-beds]").each(function(){
num_beds = $(this).val();
if (num_guests > num_beds) {
$(this).parent().hide(); // this should be the tablerow
}
});
});
});
</script>
<table>
<thead>
<th>Room Type</th>
<% @bookingdetails['result']['availableDates'].each do |room| %>
<th><% z = Date.parse room %><%= z.month %>/<%= z.day%>/<%= z.year %></th>
<% end %>
<th>Total Cost (per person)</th>
</thead>
<tbody>
<% i = 1 %>
<% @bookingdetails['result']['roomTypes'].each do |room| %>
<tr id="row-<%= i %>">
<td id="roomtype-<%= i %>" class="roomdescription">
<h5><%= room['description'] %></h5>
</td>
<% room['availability'].values.flatten.each do |avail| %>
<td id="avail-<%= i %>" data-num-beds="<%= avail['beds'] %>" class="bookingcell">
<!-- # of Beds: --> <%= avail['beds'] %> |
<!--Price in USD: --><% @price = avail['price'].to_f %><%= number_to_currency(@price) %>
</td>
<% end %>
<td class="costcell">
<% @totalcost = number_to_currency(@price * @bookingdetails['result']['availableDates'].length) %><%= @totalcost %>
<input type="radio" name="roomcode" value=<%="#{room['code']}" %> />
</td>
</tr>
<% i += 1 %>
<% end %>
</table>
@xentek
Copy link

xentek commented Mar 5, 2012

<script>
    $(document).ready(function(){
        $(":hidden").show();
        $('#guests').live('change', function() {
            var num_guests = $(this).val();
            $("td[data-num-beds]").each(function(index, elem){
                num_beds = $(elem).val();
                if (num_guests > num_beds) {
                    $(elem).parent().hide(); // this should be the tablerow
                }
            });
        });
    });
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment