1

We're trying to clear a textarea in a form using jQuery.

It works in Safari and Chrome, but not in Firefox. The problem in FireFox is that it is clearing the text in the source (according to firebug) but not in the normal browser display.

The code we are using is:

$("#text_areas_id").val("");

Is anyone aware of a bug in Firefox 4 with this?

Our guess is that we need to somehow re-render the textarea for firefox after we change its vallue. We read some people had similar problems in Opera and fixed it by setting the css of the text area to display:block, but we didn't have any luck with this.

We are using FireFox 4.01 on Mac & Firebug 1.7.0

Thanks for any assistance you can offer!

braX
  • 11,506
  • 5
  • 20
  • 33
salonMonsters
  • 1,237
  • 3
  • 16
  • 26
  • I'm not sure what else is going on, here, but your approach works for me (Firefox 4/Ubuntu 11.04): [JS Fiddle](http://jsfiddle.net/davidThomas/Uh6T6/). – David Thomas May 02 '11 at 21:38

2 Answers2

2

Have you tried using text() instead of val()?

$("#text_areas_id").text("");
Mark Pope
  • 11,244
  • 10
  • 49
  • 59
  • Right! Remember: `.val()` is for `input` – Roko C. Buljan May 02 '11 at 21:35
  • Does .val() remove the default text? Or just user input? – Mark Pope May 02 '11 at 21:38
  • 1
    Yes, we tried text and it does put the text into the source, but not into the textarea as rendered by the browser, just like val does. We also understand that being an input we should be using val() – salonMonsters May 02 '11 at 21:41
  • running .val("") doesn't remove any text from the text area rendered by firefox. It does however appear to be removing the text from the textarea in the source when we look at it through firebug. It appears that it is being removed ok, but firefox is not refreshing the display textarea after the change. – salonMonsters May 02 '11 at 21:42
  • > Seems like it's working. I remember I had trouble on this thematic but I think I confused it regards setting .attr('value') or just using .val() !! :) My bad! Well. Here are a bit more explanations: [L I N K](http://stackoverflow.com/questions/415602/set-value-of-textarea-in-jquery) – Roko C. Buljan May 02 '11 at 22:48
2

I have just tried your solution in Firefox 4.0.1 and seems to work: http://jsfiddle.net/8NEzR/8/

bicccio
  • 384
  • 1
  • 19
  • Now I'm feeling a bit stupid for not trying that, that does indeed work. I'm guessing it must be something else in our code that is causing it. We'll pull that bit out and try to isolate it better. – salonMonsters May 02 '11 at 21:48
  • @Minirobot --> Well. nice. Here are a bit more explanations: [L I N K](http://stackoverflow.com/questions/415602/set-value-of-textarea-in-jquery) – Roko C. Buljan May 02 '11 at 22:41