Domanda

One year ago, I was looking for about autoresize textarea and I found it here, at that time this script works fine in jsfiddle, but now it does not work, I got an error message on console browser looks like :

Uncaught ReferenceError: autoresize is not defined

I tried to make it on my computer as index.html, and it works.

My question, why is it not working now in jsfiddle? Sorry, maybe my question is not so important, I'm just curious, is this an error in jsfiddle, or error in script?

function autoresize(textarea) {
    textarea.style.height = '24px';
    textarea.style.height = textarea.scrollHeight + 12 + 'px';
}
È stato utile?

Soluzione

It's that damned useful onLoad wrapper:

Just change it to No wrap:

... and it will work. It didn't work because your autoresize function was wrapped in onLoad handler, which made not possible to find your function in the scope.

DEMO: http://jsfiddle.net/ErWxU/2/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top