473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

i'm able to read the value of a TEXTAREA in IE but not in FireFox


I wanted to teach myself AJAX this weekend so I sat down with Stuart
Landgridge's book and I started to play around. I came up with a little
page that you can add text and images to. You can see it here:

http://www.publicdomainsoftware.org/ajaxExperiment.htm

Click in any box to get the controls with which you can play around.

This function below, askForInput, was working the way I wanted, till I
tried to give it two parameters, one of which was meant to be example
text that would auto-fill the TEXTAREA and give it an intitial value.
While things still work find in IE, now this works incorrectly in
FireFox. In FireFox, whatever value is set initially in this function
becomes the only function that can later be retrieved. Obviously, that
is not what I want. If the software asks people to write in some text,
it should be what they write, and not the initial value, that is then
captured and used. What syntax do I have to use to set the initial
value to FireFox will still see the value that the user types in,
rather than the initial value set here?
function askForInput(introText, exampleText) {
var divRef = getRefToInputDiv();
var communicationBoxRef =
document.getElementById("communicationBox");
communicationBoxRef.style.display = "block";
communicationBoxRef.appendChild(divRef);
divRef.style.display = "block";

var area = document.getElementsByTagName('TEXTAREA')[0];
area.value = exampleText;
var divRef = document.getElementById("inputBox");
if (divRef.innerHTML == "" || divRef.innerHTML == undefined) {
divRef.innerHTML = exampleText;
}

var divRef = document.getElementById("inputDiv");
var firstChildNode = divRef.firstChild;
if (divRef.childNodes.length > 4) {
divRef.removeChild(firstChildNode);
firstChildNode = divRef.firstChild;
}
var newTextNode = document.createTextNode(introText);
var newLiterature = document.createElement("p");
newLiterature.appendChild(newTextNode);
var firstChildNode = divRef.firstChild;
divRef.insertBefore(newLiterature, firstChildNode);
}

function getInput() {
var divRef = document.getElementById("inputBox");
var inputText = divRef.innerHTML;
divRef.innerHTML = "";
if (inputText == "" || inputText == undefined) {
var area = document.getElementsByTagName('TEXTAREA')[0];
inputText = area.value;
area.value = "";
}
inputResults = inputText;

var communicationBoxRef =
document.getElementById("communicationBox");
var lastChildInCommunicationBox = communicationBoxRef.lastChild;
communicationBoxRef.removeChild(lastChildInCommuni cationBox);
communicationBoxRef.style.display = "none";

if (nextActionToTakeAfterInput == "setTextAction")
setTextAction();
if (nextActionToTakeAfterInput == "setImageAction")
setImageAction();
if (nextActionToTakeAfterInput == "setHtmlAction")
setHtmlAction();
if (nextActionToTakeAfterInput == "setBackgroundColorAction")
setBackgroundColorAction();
if (nextActionToTakeAfterInput == "setColorAction")
setColorAction();
}

Feb 5 '06 #1
4 7990
Jake Barnes wrote:
I wanted to teach myself AJAX this weekend so I sat down with Stuart
Landgridge's book and I started to play around. I came up with a little
page that you can add text and images to. You can see it here:

http://www.publicdomainsoftware.org/ajaxExperiment.htm

Click in any box to get the controls with which you can play around.

This function below, askForInput, was working the way I wanted, till I
tried to give it two parameters, one of which was meant to be example
text that would auto-fill the TEXTAREA and give it an intitial value.
While things still work find in IE, now this works incorrectly in
FireFox.
Because of your use of the proprietary innerHTML where you should have
been using standards.
In FireFox, whatever value is set initially in this function becomes the only function that can later be retrieved. Obviously, that
is not what I want. If the software asks people to write in some text,
it should be what they write, and not the initial value, that is then
captured and used. What syntax do I have to use to set the initial
value to FireFox will still see the value that the user types in,
rather than the initial value set here?
Get the value of the text area, not the innerHTML.

[...]
function getInput() {
var divRef = document.getElementById("inputBox");
divRef is actually a reference to a textarea element, the name is
misleading. The ID "inputBox" is also misleading, give your variables
better names (I guess this is a work in progress and you likely just
started with names that seemed like a good idea at the time, but now the
names are not appropriate so fix 'em).

var inputText = divRef.innerHTML;
innerHTML has no public specification and is implemented differently in
different browsers. Here you have found one of those differences - in
IE, the innerHTML of the textarea is updated to reflect user input, in
Firefox it isn't, it keeps the default value.

You shouldn't use innerHTML here anyway: the value of the input is in
its value property:

var inputText = divRef.value;

divRef.innerHTML = "";


divRef.value = "";
[...]
--
Rob
Feb 6 '06 #2

RobG wrote:
Jake Barnes wrote:
I wanted to teach myself AJAX this weekend so I sat down with Stuart
Landgridge's book and I started to play around. I came up with a little
page that you can add text and images to. You can see it here:

http://www.publicdomainsoftware.org/ajaxExperiment.htm

Click in any box to get the controls with which you can play around.

This function below, askForInput, was working the way I wanted, till I
tried to give it two parameters, one of which was meant to be example
text that would auto-fill the TEXTAREA and give it an intitial value.
While things still work find in IE, now this works incorrectly in
FireFox.


Because of your use of the proprietary innerHTML where you should have
been using standards.


Actually, I was trying to use a variety of methods to get the value,
but now I realize that the way I was testing was flawed:

var divRef = document.getElementById("inputBox");
var inputText = divRef.innerHTML;
divRef.innerHTML = "";
if (inputText == "" || inputText == undefined) {
var area = document.getElementsByTagName('TEXTAREA')[0];
inputText = area.value;
area.value = "";
}
inputResults = inputText;
I suppose I should put the more standard approach first, and if its
empty, I can assume that perhaps I'm dealing with IE, at which I can
look in innerHTML.

Feb 6 '06 #3
Jake Barnes wrote:
RobG wrote:
Jake Barnes wrote:
I wanted to teach myself AJAX this weekend so I sat down with Stuart
Landgridge's book and I started to play around. I came up with a little
page that you can add text and images to. You can see it here:

http://www.publicdomainsoftware.org/ajaxExperiment.htm

Click in any box to get the controls with which you can play around.

This function below, askForInput, was working the way I wanted, till I
tried to give it two parameters, one of which was meant to be example
text that would auto-fill the TEXTAREA and give it an intitial value.
While things still work find in IE, now this works incorrectly in
FireFox.
Because of your use of the proprietary innerHTML where you should have
been using standards.

Actually, I was trying to use a variety of methods to get the value,
but now I realize that the way I was testing was flawed:


Just use the value property, never use innerHTML to get the value of a
textarea element (or input element). You are using getElementById
without any testing, what browser supports that but not the value property?

[...]
I suppose I should put the more standard approach first, and if its
empty, I can assume that perhaps I'm dealing with IE, at which I can
look in innerHTML.


No, don't. IE introduced support the value property with IE 3 and
innerHTML with IE 4, so that is futile. Any browser that supports AJAX
will support the textarea value property (and nearly all other HTML 4
attributes).

innerHTML should only be used sparingly and for non-essential purposes,
e.g. to write some simple text or HTML that replaces the content of an
element.
--
Rob
Feb 6 '06 #4

RobG wrote:
Jake Barnes wrote:
RobG wrote:
Jake Barnes wrote:

I wanted to teach myself AJAX this weekend so I sat down with Stuart
Landgridge's book and I started to play around. I came up with a little
page that you can add text and images to. You can see it here:

http://www.publicdomainsoftware.org/ajaxExperiment.htm

Click in any box to get the controls with which you can play around.

This function below, askForInput, was working the way I wanted, till I
tried to give it two parameters, one of which was meant to be example
text that would auto-fill the TEXTAREA and give it an intitial value.
While things still work find in IE, now this works incorrectly in
FireFox.

Because of your use of the proprietary innerHTML where you should have
been using standards.

Actually, I was trying to use a variety of methods to get the value,
but now I realize that the way I was testing was flawed:


Just use the value property, never use innerHTML to get the value of a
textarea element (or input element). You are using getElementById
without any testing, what browser supports that but not the value property?


Oh, that's good to know. I figured I'd go back and add in testing for
getElementById eventually, but its good to know that any browser with
getElementById support also supports values in the area of textarea.


I suppose I should put the more standard approach first, and if its
empty, I can assume that perhaps I'm dealing with IE, at which I can
look in innerHTML.


No, don't. IE introduced support the value property with IE 3 and
innerHTML with IE 4, so that is futile. Any browser that supports AJAX
will support the textarea value property (and nearly all other HTML 4
attributes).


Wow. I had no idea. That's good to know.

innerHTML should only be used sparingly and for non-essential purposes,
e.g. to write some simple text or HTML that replaces the content of an
element.


So there is a valid use for innerHTML?

Feb 6 '06 #5

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

Similar topics

12
by: Phil Powell | last post by:
The customer made a wild request: they want on their admin panel a textarea that will display an existing resume. This textarea, however, must have a dynamic width, one that "fills the screen...
3
by: Roderik | last post by:
Hi, On http://www.cyl.nl/tips/index.html you see a textarea. In firefox the textarea falls over the border of the form, in internet explorer it fits exactly into the form. Any idea how to get...
3
by: Fluffy Convict | last post by:
I am trying to write a script that changes a textarea wrap realtime, basically like you can switch to and from "wordwrap" in Microsofts Notepad. Because of a bug...
3
by: honcho | last post by:
Hello: When my web application is invoked by Firefox the height and width information is passed to Internet Explorer but not to Firefox. The ASP.NET control is <asp:textbox id="tbxNote"...
6
by: Tony | last post by:
The w3schools HTML tag reference for <textarea> http://www.w3schools.com/tags/tag_textarea.asp says that the attributes 'cols' and 'rows' are REQUIRED attributes for the textarea tag. Looking at...
2
by: xhe | last post by:
I met a very headache problem in javascript, I think this might be difference between IE and NS / Safari. I have a text area <form> <textarea name='tex1' onkeyup='displayit();'></textarea>...
0
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi everyone! I have these three questions and though to post them in a single thread: 1) I have created a textarea: <textarea id="txtCards" cols="50" rows="15" runat="server" wrap="virtual"...
8
by: McKirahan | last post by:
Why does the following happen? How can it be suppressed? Under Firefox, use the left-mouse button to drag any image into the textarea and 52 copies of the image's URL appear! <html> <body>...
5
by: laredotornado | last post by:
Hi, If my variable contains var v = "Hi<BR/>there<BR/>"; and attempt to set the value of my textarea like so: dojo.byId("appEditForm:txtDesc").value = v;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.