Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8619033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:14:52+00:00 2026-06-12T06:14:52+00:00

I require Cross compatability IE7 upwards For an event listener. Due to the system

  • 0

I require Cross compatability IE7 upwards For an event listener. Due to the system I am using I can only use an external js file to create the listeners.
I wish to create a rule for all textarea boxes, making they increase in height when they wrap the text meaning that you never have to scroll (They need to be printed with all the text showing). This works fine using addEventListener, but because I can’t uses THIS I can not get this to work generically using attachEvent.

<html>
<style>
input[type="text"], textarea{ width:10%;}
</style>
<script>
function gettext(){
var x=document.getElementsByTagName("textarea");
var ent; 
for(i = 0; i < x.length; i++){
if (x.item(i).addEventListener) {
    x.item(i).addEventListener("keyup", function () {ChangeDepth(this)}, false)
    x.item(i).addEventListener("mouseup", function () {ChangeDepth(this)}, false)
    x.item(i).addEventListener("change", function () {ChangeDepth(this)}, false)
 }            
 else {
   ent = document.getElementById(x.item(i).id)
   x.item(i).attachEvent ("onkeyup", function () {ChangeDepth(ent)});
   x.item(i).attachEvent ("onmouseup", function () {ChangeDepth(ent)});
   x.item(i).attachEvent ("onchange", function () {ChangeDepth(ent)});

  }
}
}

function ChangeDepth(e){
var t = e.scrollHeight +'px';
if ((e.clientHeight < e.scrollHeight)||(e.clientHeight > e.scrollHeight)){e.style.height = t ;}
}
</script>
<body onload="gettext()">
<p>(Type in the textarea box when the text wraps it will increase the height of the box)<br />
<textarea name="c" cols="" rows="1" id="c"  ></textarea>
<br />
<textarea name="f" cols="" rows="1" id="f"  ></textarea></p>
</body>
</html>

This only works for the last textarea field in IE 8. I am assuming this because It only has the value of the last object.
No idea what to do next

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:14:53+00:00Added an answer on June 12, 2026 at 6:14 am

    http://jsfiddle.net/KAy9a/

    function wireUp() {
        console.log('wiring');
        var x = document.getElementsByTagName("textarea");
        var ent;
        for (i = 0; i < x.length; i++) {
            if (x.item(i).addEventListener) {
                x.item(i).addEventListener("keyup", ChangeDepth, false)
                x.item(i).addEventListener("mouseup", ChangeDepth, false)
                x.item(i).addEventListener("change", ChangeDepth, false)
            }
            else {
                x.item(i).attachEvent("onkeyup", ChangeDepth);
                x.item(i).attachEvent("onmouseup", ChangeDepth);
                x.item(i).attachEvent("onchange", ChangeDepth);
    
            }
        }
    }
    
    function ChangeDepth(e) {
        // instead of passing in the element, we get the Event object
        // we can then get the event target (or srcElement) to know where the event came from    
        e = e || event;
        e = e.target || e.srcElement;
    
        // the code below is the same you had before:
        var t = e.scrollHeight + 'px';
        if ((e.clientHeight < e.scrollHeight) || (e.clientHeight > e.scrollHeight)) {
            e.style.height = t;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use Sencha Touch 2 to load a local json file into
XMLHttpRequest s require CORS to work cross-domain. Similarly for web fonts, WebGL textures, and
Looking at adobe flex for cross-platform mobile apps. Does the final apps require adobe
What is the recommended (cross-browser) video format to use on websites so that users'
I'm writing a cross-platform C++ program using Qt and I want to package/embed a
What is the main purpose of using CROSS APPLY ? I have read (vaguely,
I'm trying to move to HTML5 on new projects, that don't require high cross-browser-ism.
I'm looking into using the Mono framework for taking my current C# application cross-platform
I have a class that I want to use in many test cases: require
I can't find this anywhere and i don't know why the cross domain REST

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.