user2079902
user2079902

Reputation: 23

How do I hide a field given a checked box?

I am trying to create a dynamic query page. I am more than happy to learn ruby on rails which is what I am currently doing. However there is a time constraint for this and I have been searching high and low on how to hide a field on a form if a checkbox is checked. I have next to nothing ruby skills and I cant change to another language. Any assistance would be greatly GREATLY appreciated. Also if you know a good tutorial for doing query pages would help!!!

Upvotes: 0

Views: 94

Answers (1)

Nick Veys
Nick Veys

Reputation: 23939

For a form like:

<form ...>
  <input id="hide-box" type="checkbox" />
  <input id="field-to-hide" />
</form>

You'll need to use something like JQuery to listen for checking and hide accordingly.

$('#hide-box').on('change', function() {
  $('#field-to-hide').toggle($(this).prop('checked'));
});

Upvotes: 1

Related Questions