最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

internet explorer 7 - How to finddetect any textarea in page in javascript - Stack Overflow

programmeradmin8浏览0评论

(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.

(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.

Share Improve this question edited Jan 4, 2010 at 22:31 yogsma asked Jan 4, 2010 at 20:39 yogsmayogsma 10.6k31 gold badges106 silver badges157 bronze badges 2
  • OK, not sure I quite get it yet - when you say "I select a drop-down option for sending email, so my textarea for email shows up", is the textarea already part of the page (but hidden) or is it dynamically created when you select the dropdown? Looks like that RTE works by hiding the textarea and replacing it with an iframe, so if the textarea is already hidden and made visible when you select from the dropdown this would partially explain the behaviour you see in IE. Sorry, might need to see actual code to help with a solution though, there are too many potential factors here. – Will Prescott Commented Jan 4, 2010 at 23:18
  • You have pretty much got what I intended to say. textarea is hidden. It shows up on selection of drop-down option. Why doesn't IE behave as firefox in this kind of javascript scenario , you think? – yogsma Commented Jan 5, 2010 at 2:53
Add a comment  | 

4 Answers 4

Reset to default 12
document.getElementsByTagName('textarea').length > 0

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?

Pure JavaScript (You can use this code)

textarea is HTML element tag

JavaScript :

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

}

HTML CODE:

<div class="flavor">

  <div class="value">

    <textarea name="name" rows="8" cols="80"></textarea>

  </div>

</div>

<script type="text/javascript">

  var flavorbox = document.getElementsByClassName('flavor')[0]  
                          .getElementsByClassName('value')[0]
                          .getElementsByTagName('textarea').length;

  alert(flavorbox);

</script> 

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.

发布评论

评论列表(0)

  1. 暂无评论