473,503 Members | 5,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript and DOM textarea onblur issue.

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!

Apr 18 '07 #1
1 2702
jb****@gmail.com said the following on 4/18/2007 4:14 PM:
Hello everyone!
<snip>
//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/
Apr 18 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4497
by: CW | last post by:
I wrote an HTML based chat application. The front end is built entirely on HTML + javascript. Essentially, I have a hidden frame that's refreshed frequently and any new messages are displayed in...
4
8923
by: Greg | last post by:
I'm guessing the problem I'm having has something to do with Master Pages or DetailsView because the exact same code works fine on a page without a Master Page and DetailsView controls. The...
1
1399
by: gpo | last post by:
I've done a form validation and I want to submit the form details output into the HTML page,so that I can view the details. How can you doing it using innerHTML here's the form code. <form ...
1
3826
by: wkerplunk | last post by:
Below is what I have build with several different languages. It works great but I need help, I am stuck. When you click on an item in the dropdown autocomplete div it does a mousedown function...
1
1619
by: filmfanatic | last post by:
In this emal form, I'm trying to consolidate all the input into the TEXTAREA portion and then have it emailed to a specific person. I've tried the onClick and onBlur commands but only one field's...
2
1206
by: wannasee | last post by:
Hi Folks, I have two issues: 1- I have written following code a code that works in IE but not in firefox. Please see code below. JavaScript version is 1.3. Both browsers should be able to run...
4
3099
by: sureshl | last post by:
function cal() { var f = document.form1; var regExp_Count = new RegExp("^+$"); f.price1.value = parseFloat(f.baseprice.value*(f.percen.value/100)).toFixed(0); } cal() functions , will...
0
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5566
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.