Connecting Tech Pros Worldwide Forums | Help | Site Map

JavaScript and DOM textarea onblur issue.

jb5531@gmail.com
Guest
 
Posts: n/a
#1: Apr 18 '07
Hello everyone!

I am trying to implement some code for my website using JavaScript and
DOM. The issue I'm having is that I want to change the size of the
textarea on blur. This text area changes from an input box to a
textarea once the value length reaches a certain number, passed to the
function call.

I cannot seem to reference this textarea after it is dynamically made
in order to change it's size (I am attempting to collapse it onblur
and have it expand onfocus). Any help is greatly appreciated! The code
is below:


<script type="text/javascript">
<!--
function xff(theID, fieldStart, fieldLimit, fieldRows) {

var theObj = document.getElementById(theID);
var saved='';
var origSize = theObj.size;
var currSize;
var len = origSize;
var newTextArea;

theObj.onkeyup = function() {
if(theObj.value.length >= fieldStart && theObj.value.length <
fieldLimit) {
theObj.size = theObj.size+1;
}
if((fieldRows && fieldRows != "undefined") && theObj.value.length >=
fieldLimit) {
newTextArea = document.createElement("textarea");
newTextArea.setAttribute("cols", fieldLimit);
newTextArea.setAttribute("rows", fieldRows);
newTextArea.value = theObj.value;
newTextArea.setAttribute("name", theObj.getAttribute("name"));
theObj.parentNode.replaceChild(newTextArea, theObj);
newTextArea.setAttribute("id", theID);
newTextArea.focus();
}
}

theObj.onblur = function() {
if (theObj.value.length len) {
saved = theObj.value;

var trunc = theObj.value.substring(0, len) + '...';
theObj.value = trunc;
currSize = theObj.size;
}
theObj.size = origSize;
}


theObj.onfocus = function() {
if(saved != ''){
theObj.size = currSize;
}
theObj.value = saved;
}
//THIS IS WHAT I CAN'T GET WORKING!!!//
textareas=document.getElementById("theID");
textareas.onblur = function() {
textareas.setAttribute('cols', 3);
textareas.setAttribute('rows', 3);
}
}
-->
</script>

<script language="JavaScript" type="text/javascript">



This code is called in the HTML by, for example: xff("ff",10,30,10);


Thanks for reading and helping if you can!


Randy Webb
Guest
 
Posts: n/a
#2: Apr 18 '07

re: JavaScript and DOM textarea onblur issue.


jb5531@gmail.com said the following on 4/18/2007 4:14 PM:
Quote:
Hello everyone!
<snip>
Quote:
//THIS IS WHAT I CAN'T GET WORKING!!!//
textareas=document.getElementById("theID");
textareas.onblur = function() {
textareas.setAttribute('cols', 3);
textareas.setAttribute('rows', 3);
textareas.cols = 3;
textareas.rows = 3;

setAttribute is known to be buggy in IE.

Is there a run on setAttribute today?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Closed Thread


Similar JavaScript / Ajax / DHTML bytes