views:

244

answers:

3

(document.getElementById('textarea').length > 0) doesn't work. Does anyone know anything else other than this?

Will

Here is the scenario from my previous question which was unanswered. I have Rich text Editor(Openwysiwyg) which is loaded into textarea when I go to that particular page where textarea is placed. The function uses textarea id to identify textarea to replace it with Rich Text Editor(RTE). Now the script to call this function is in header part of the page. I select a drop-down option for sending email, so my textarea for email shows up. With this script added for RTE, my textarea for email is replaced by RTE and I can send formatted emails. So this works perfectly fine in Firefox. With IE7, RTE shows up even before I select drop-down option for email and this makes whole page messed up.When I select drop-down option for email, I just see normal text area and RTE still sitting at top of page.

+7  A: 

document.getElementsByTagName('textarea').length > 0

Zaje
+1  A: 

You can use (note the plural form!)

var e = document.getElementsByTagName("textarea");

You can use jQuery as well:

$("textarea").each( function() { /* ... */ } );

EDIT: I faced a similar problem once. I was using fckedit, and when I tried reading the value of my textedit (document.getElementById('blabla').value) I was getting null, even tough the rich text edit was ddefinetly showing something on screen.

It turns out that the fckedit API opens a new element on top of the textearea, and only when you navigate from the page is syncs it's internal data (which is on an iframe, if I am not mistaking) into the original textarea.

The moral of the story: if you are using some richtext API - use it's API to query the status of your "textarea". Hope this helps you, as I don't know the library you are using.

PS: I actually used $("blabla").val() ... which is also JavaScript... for some reason people think that jQuery is not javascript. Why is that?

elcuco
Dont understand why do people give Javascript answers by saying you can use JQuery as well. Agreed its a good library and stuff, why unnecessarily say "You can use JQuery as well" when it can be solved with normal Javascript.
Zaje
I am just educating towards other options. If I knew Prototype, I would give an example as well.
elcuco
Thanks guys, but this hasn't helped me. I tried this , but the javascript which is included after the if clause in which I am checking for textarea, is never called.
yogsma
Try document.getElementsByTagName('textarea')[0].length
Zaje
I have only one textarea, so no question of checking it arraywise. Also I would like to emphasize I am facing this issue with internet explorer , things work perfectly fine in Firefox without any conditions.
yogsma
Zaje, see the answer below by mastermind for why people suggest jQuery. There are a lot of people in the world that don't know javascript as well as you and sometimes they don't know about jQuery.
Chuck Vose
Also, the OP never said anything that suggests that they don't want to use jQuery.
Chuck Vose
Think we might need a little more context about exactly what your scenario is here - e.g. is the textarea definitely in the DOM before the script is called? There's no reason that I can see why Zaje's original suggestion shouldn't work in IE7, everything else being equal.
Will Prescott
Will, I edited the original question. Check the scenario.
yogsma
People suggest that you should use jQuery because it was created to make things like this easier.
Alex JL
ok guys, But my question is for Javascript and not for JQuery.
yogsma
A: 

Since openWYSIWYG generates a iframe on the fly, its not so simple to get/set its content.

I am currently working on changing these settings in the source. will post here a link as soon as i get the changes.

adardesign