# AJAX: getting a label to act like its field

**URL:** <https://www.ruby-forum.com/t/ajax-getting-a-label-to-act-like-its-field/171808>\
**Category:** Rails\
**Created:** [July 9, 2009, 2:58pm UTC](https://www.ruby-forum.com/t/ajax-getting-a-label-to-act-like-its-field/171808 "2009-07-09T14:58:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [July 9, 2009, 2:58pm UTC](https://www.ruby-forum.com/t/ajax-getting-a-label-to-act-like-its-field/171808/1 "2009-07-09T14:58:28Z")

</div>

Hi,

I have a check\_box and on activating it, I want an extra field to show  
up.

I thought I’d do this by calling a remote\_function called “toggle”  
in :onchange. In toggle.rjs, I’d do something like page.toggle and  
have the visibility toggled. I’m not sure whether it works: I haven’t  
tried it yet. What I did try was setting up a form with a hidden field  
(by default the check\_box isn’t ticked, so the field should be  
hidden), but the field label is still there. Is there a way to do this  
so I can toggle both the field and the label?

Any other suggestions to do this (without page.toggle maybe?) are very  
welcome as well.

Thank you.

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [July 9, 2009, 3:58pm UTC](https://www.ruby-forum.com/t/ajax-getting-a-label-to-act-like-its-field/171808/2 "2009-07-09T15:58:15Z")

</div>

On Jul 9, 2:56 pm, jhaagmans [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> hidden), but the field label is still there. Is there a way to do this  
> so I can toggle both the field and the label?
> 
> Any other suggestions to do this (without page.toggle maybe?) are very  
> welcome as well.

Call page.toggle twice - once on the label, once on the field ?

Fred

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [July 9, 2009, 4:08pm UTC](https://www.ruby-forum.com/t/ajax-getting-a-label-to-act-like-its-field/171808/3 "2009-07-09T16:08:48Z")

</div>

On Thu, Jul 9, 2009 at 9:57 AM, Frederick  
Cheung[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > (by default the check\_box isn’t ticked, so the field should be  
> > hidden), but the field label is still there. Is there a way to do this  
> > so I can toggle both the field and the label?
> > 
> > Any other suggestions to do this (without page.toggle maybe?) are very  
> > welcome as well.
> 
> Call page.toggle twice - once on the label, once on the field ?

Or put both the label and the field in an enclosing element (e.g. a  
span or a div) and toggle visibility on that.

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Twitter: [http://twitter.com/RickDeNatale](http://twitter.com/RickDeNatale)  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [July 9, 2009, 4:36pm UTC](https://www.ruby-forum.com/t/ajax-getting-a-label-to-act-like-its-field/171808/4 "2009-07-09T16:36:18Z")

</div>

Thank you both, I had specified an id for the label and called  
page.toggle on it as Frederick suggested, but I suspected a label to  
be able to do more than that. Apparently not. This will do the trick.

Is there a way to toggle an object directly from :onchange, by the way?
