Skip to content

Instantly share code, notes, and snippets.

@dnch
Created March 5, 2009 02:15
Show Gist options
  • Save dnch/74140 to your computer and use it in GitHub Desktop.
Save dnch/74140 to your computer and use it in GitHub Desktop.
## application.js
trigger_visibility_callbacks = function() {
$$(".conditional").each(function(e) {
eval(e.id + "_callback")
});
}
## view.html.erb
<% form_for @foo do |f| %>
<h1>Question One</h1>
<p>Lorem ipsum dolor sit amet?</p>
<%= f.radio_button(:question_one, "yes", :onchange => "trigger_visibility_callbacks" %> Yes
<%= f.radio_button(:question_one, "no", :onchange => "trigger_visibility_callbacks" %> No
<%= f.radio_button(:question_one, "maybe", :onchange => "trigger_visibility_callbacks" %> Maybe
<!-- conditional div one -->
<div class="conditional" id="question_one_a">
Questicant ipsum floor?
</div>
<script type="text/javascript">
question_one_a_callback = function() {
self = $('question_one_a');
$F('question_one').value == "yes" ? self.show() : self.hide();
}
</script>
<!-- conditional div two -->
<div class="conditional" id="question_one_b">
Gleeple Glarble Bleeply Boogle?
</div>
<script type="text/javascript">
question_one_b_callback = function() {
self = $('question_one_b');
$F('question_one').value == "no" ? self.show() : self.hide();
}
</script>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment