473,404 Members | 2,174 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,404 software developers and data experts.

Whacked out contentEditable/color weirdness

I am going nuts on this. Am I just blind, or is there some bug either in my code or IE?

Nutshell version: I have a content editable div that is supposed to show its entry in red if it is not what it
started out with. This works, EXCEPT if the content is completely erased(!) character by character, starting from
the right(!). In that case, the color gets stuck on red. I've made a web page for this at
http://csaba.org/demoDiv.htm The uncommented version appears below.

The thing that makes this so massively weird to me is that the behaviour seems to stem from the way in which a
boolean variable is set. If you look at the code below, you'll see that nonEmpty is supposed to be a boolean. In
fact, the color value that the iff returns is correct, and it gets set, and evidently ignored. If the nonEmpty = ...
line is commented out, however, then the line above it takes over, which is doing the same thing as the commented out
line. With the difference that the font color is now reset properly.

I'd love to be enlightened on this or know where I can delve further.

Thanks,
Csaba Gabor from New York

The short form of the demo page follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD>
<META http-equiv="content-type" content="text/html;charset=iso-8859-1">
<TITLE>color problem</TITLE>
<SCRIPT>
function divPrep() {
myDiv = document.getElementsByTagName("DIV")[0];
myDiv.saveText = myDiv.outerText;
}
function cellChange() {
var nonEmpty;
if (myDiv.outText!="") nonEmpty=true; else nonEmpty=false;
nonEmpty = (myDiv.outerText!="");
myDiv.style.color =(myDiv.saveText!=myDiv.outerText && nonEmpty) ? "red" : "";
}
</SCRIPT>
</HEAD>
<BODY onLoad="divPrep()">
<TABLE border=1><TR><TD><DIV accesskey=i contentEditable onKeyUp="cellChange()">DIV</DIV></TD></TR></TABLE>
</BODY>
</HTML>

Jul 20 '05 #1
1 1888
I have since isolated the problem and posted my observations in
microsoft.public.windows.inetexplorer.ie55.program ming.dhtml.scripting

The bug is that if you try to change the font .style.color on an
empty DIV under certain conditions (deleting the final, unselected
character with the backspace key), it kills being able to set .style.color
for the DIV for the rest of that page's session

Apropos, in the code that I posted in this group there is a typo in the
second line of cellChange: myDiv.outText should have been myDiv.outerText
Had that been the case, the commented out version also would not have worked.

However, by changing cellChange as follows, the problem can be circumvented:
function cellChange() {
var oT = myDiv.outerText;
if (myDiv.outerText!="")
myDiv.style.color =(myDiv.saveText!=oT && oT!="") ? "red" : "";
}

Regards,
Csaba Gabor from New York
Jul 20 '05 #2

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

Similar topics

2
by: gboissiere | last post by:
Hello 'contentEditable' gurus, The example code below uses contentEditable to let the user edit the <div> element directly in their browser. Works also using designMode for the document. ...
1
by: trevordixon | last post by:
I have an DIV with the contentEditable attribute. How can I get the value of the content within that DIV after the user has edited it for further processing. I'd like to store the HTML code within...
2
by: Dung Ping | last post by:
I like to see following to happen: When typing a number of 1 to 4 immediately after an alphabetic letter, it would become corresponding superscript. But if the user leaves a space after the...
3
by: nAmYzArC | last post by:
Hello every1, I have a "<DIV" tag with contenteditable turned on. I am using this as an area that users can either paste or drag/drop text into. The text can come from other browser windows and of...
5
by: David Thielen | last post by:
Hi; I am creating png files in my ASP .NET app. When I am running under Windows 2003/IIS 6, the file is not given the security permissions it should have. It does not have any permission for...
1
by: dharshanav | last post by:
Hi All, Is there a way to make the Mozilla browser behave the same way as IE when using in the design mode? For IE: <div id="left_div" contenteditable="true" frameborder="no"...
1
by: delraydog | last post by:
Does a contentEditable DIV have the notion of an internal document? I'm trying to convert code that uses an IFrame.contentWindow.document to use the "document" inside a contentEditable DIV but they...
2
by: JYA | last post by:
Hi. I was writing an xmltv parser using python when I faced some weirdness that I couldn't explain. What I'm doing, is read an xml file, create another dom object and copy the element from...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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...
0
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...
0
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...

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.