473,583 Members | 3,386 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(int roText, exampleText) {
var divRef = getRefToInputDi v();
var communicationBo xRef =
document.getEle mentById("commu nicationBox");
communicationBo xRef.style.disp lay = "block";
communicationBo xRef.appendChil d(divRef);
divRef.style.di splay = "block";

var area = document.getEle mentsByTagName( 'TEXTAREA')[0];
area.value = exampleText;
var divRef = document.getEle mentById("input Box");
if (divRef.innerHT ML == "" || divRef.innerHTM L == undefined) {
divRef.innerHTM L = exampleText;
}

var divRef = document.getEle mentById("input Div");
var firstChildNode = divRef.firstChi ld;
if (divRef.childNo des.length > 4) {
divRef.removeCh ild(firstChildN ode);
firstChildNode = divRef.firstChi ld;
}
var newTextNode = document.create TextNode(introT ext);
var newLiterature = document.create Element("p");
newLiterature.a ppendChild(newT extNode);
var firstChildNode = divRef.firstChi ld;
divRef.insertBe fore(newLiterat ure, firstChildNode) ;
}

function getInput() {
var divRef = document.getEle mentById("input Box");
var inputText = divRef.innerHTM L;
divRef.innerHTM L = "";
if (inputText == "" || inputText == undefined) {
var area = document.getEle mentsByTagName( 'TEXTAREA')[0];
inputText = area.value;
area.value = "";
}
inputResults = inputText;

var communicationBo xRef =
document.getEle mentById("commu nicationBox");
var lastChildInComm unicationBox = communicationBo xRef.lastChild;
communicationBo xRef.removeChil d(lastChildInCo mmunicationBox) ;
communicationBo xRef.style.disp lay = "none";

if (nextActionToTa keAfterInput == "setTextAction" )
setTextAction() ;
if (nextActionToTa keAfterInput == "setImageAction ")
setImageAction( );
if (nextActionToTa keAfterInput == "setHtmlAction" )
setHtmlAction() ;
if (nextActionToTa keAfterInput == "setBackgroundC olorAction")
setBackgroundCo lorAction();
if (nextActionToTa keAfterInput == "setColorAction ")
setColorAction( );
}

Feb 5 '06 #1
4 8005
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.getEle mentById("input Box");
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.innerHTM L;
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.innerHTM L = "";


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.getEle mentById("input Box");
var inputText = divRef.innerHTM L;
divRef.innerHTM L = "";
if (inputText == "" || inputText == undefined) {
var area = document.getEle mentsByTagName( '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
2548
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 width of any sized screen". Sorry but I cannot fathom how to do this! <textarea name="resume" cols="108" rows="29" wrap="physical><?= $resume...
3
9785
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 the appearance in firefox the same? kind regards, Roderik
3
6751
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 (https://bugzilla.mozilla.org/show_bug.cgi?id=302710), FireFox does not listen to the textarea.wrap = 'soft' command. Because I want the script to be cross-browser compatible,...
3
5093
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" runat="server" Width="100%" Height="226px" TextMode="MultiLine"> For IE it renders <textarea name="tbxNote" id="tbxNote"...
6
31429
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 the HTML 4.01 specification I see this, too. What I'm wondering is - 'cols' & 'rows' determines the height & width of a textarea. So shouldn't that...
2
19569
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> </form> <span id="txtValue"></span> <script language='javascript'>
0
1607
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" /> which is used for user editing (typing in some info).
8
2166
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> <form> <img src="http://www.google.com/intl/en_ALL/images/logo.gif"> <input type="reset">
5
3208
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
7821
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7929
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8190
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5697
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5370
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3814
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3841
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2328
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 we have to send another system
1
1424
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.