# Clear text\_area value onfocus

**URL:** <https://www.ruby-forum.com/t/clear-text-area-value-onfocus/112354>\
**Category:** Rails\
**Created:** [August 17, 2007, 8:48pm UTC](https://www.ruby-forum.com/t/clear-text-area-value-onfocus/112354 "2007-08-17T20:48:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 17, 2007, 8:48pm UTC](https://www.ruby-forum.com/t/clear-text-area-value-onfocus/112354/1 "2007-08-17T20:48:30Z")

</div>

Hi!

I have a “text\_area” that looks like this…

\<%= text\_area ‘business’, ‘otherDigitalDesc’, “cols” =\> 25, “rows” =\>  
4, “value” =\> “Enter Description if Yes…” %\>

Right now, if I submit it, it adds “Enter Description if Yes” into the  
database. It would be nice to not have it enter this, but if a user  
clicks on the box, it clears this out. I’m thinking of using onfocus,  
but my only fear is that if somebody clicks off and then back onto the  
box, won’t it clear their description? Is there a better/easier way  
to do this?

Thanks,  
mike

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 17, 2007, 9:42pm UTC](https://www.ruby-forum.com/t/clear-text-area-value-onfocus/112354/2 "2007-08-17T21:42:34Z")

</div>

Hey!

How about this:

“onfocus” =\> “this.value=‘’; this.onfocus=null;”

I can’t claim credit for this; I stole it from:

> **[Clearing upon first click](https://www.webmasterworld.com/javascript/3145.htm)**
>
> News and discussion for the independent webprofessional

Hope it helps though!

- Louis.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 17, 2007, 9:43pm UTC](https://www.ruby-forum.com/t/clear-text-area-value-onfocus/112354/3 "2007-08-17T21:43:35Z")

</div>

I would like to do the same thing. It would be nice to not have to  
have a label for the text field in some circumstances. I’ve seen this  
done really well but I can’t find a way to do it properly in rails. I  
don’t know what to even search for. Any ideas?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 20, 2007, 11:57pm UTC](https://www.ruby-forum.com/t/clear-text-area-value-onfocus/112354/4 "2007-08-20T23:57:37Z")

</div>

Hi!

Thanks for the information. This actually works really well…but  
now I have a second/original problem.

How do I make it so that “Enter Description if Yes” does not get  
entered into the database, while a real answer does? For example, if  
nobody clicks on the textboxes, it will enter “Enter Description if  
Yes” into the db. Is there something in the model or controller I can  
say “if value = “Enter Description if Yes” { don’t put in } else { put  
in db}”?

Thanks!  
Mike

On Aug 17, 2:41 pm, “removed\_email\_address@domain.invalid”
