Created
March 4, 2012 21:25
-
-
Save ryancurtin/1974852 to your computer and use it in GitHub Desktop.
jQuery Hiding Rows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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
commented
Mar 5, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment