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

IE not functioning on a statement that Netscape has no problem with

9
Hi,

I'm having trouble with the statement

SelectedTD = this

in the ClickTD function in the following code.

The code does the following:
the function InitTable() puts a table in the web page that has one row and one cell with an onclick handler attached to the cell .

The onclick handler (ClickTD) is supposed to do one thing when the cell in the table is clicked on, if the variable SelectedTD is equal to the object "this", and another if not. This statement does not seem to be working in IE while it does in Netscape. In IE I get an error message on the line following saying that "SelectedTD.style is null or not an object."

Can anybody explain why? How do I do what I'm trying to do in IE?
Sorry if this post is long.

Thanks,
Dave
------------------------------------------
[HTML]<HTML>
<BODY>
<SCRIPT>
var NewTABLE
var SelectedTD = null

function InitTable() {
NewTABLE = document.createElement("TABLE")
var NewTBODY = document.createElement("TBODY")

var NewTR = document.createElement("TR")
var NewTD = document.createElement("TD")
var NewTEXT = document.createTextNode("This is the contents of the cell ")

NewTD.attachEvent("onclick",ClickTD)
NewTD.style.setAttribute("cssText","color:blue",0)

NewTD.appendChild(NewTEXT)
NewTR.appendChild(NewTD)
NewTBODY.appendChild(NewTR)

NewTABLE.appendChild(NewTBODY)
document.body.appendChild(NewTABLE)
NewTABLE.setAttribute("border","3")
}

function ClickTD() {
alert("in ClickTD")

if (SelectedTD != this) {
SelectedTD = this // this statement does not work
SelectedTD.style.setAttribute("cssText","color:pur ple",0) // this statement gives an error message
}
else {
SelectedTD.style.setAttribute("cssText","color:blu e",0)
SelectedTD = null
}
}

InitTable()
</SCRIPT>
</BODY>
</HTML>[/HTML]
May 10 '08 #1
3 989
lxfc97
9
Hi,

Note that in my previous post the problem statement is not the if statement "If (SelectedTD != this)" in the ClickTD function, but rather the two statements immediately following the if statement that are supposed to be executed when the condition is true.

Sorry for the confusion.
Thanks again for the help.

Dave
May 10 '08 #2
Logician
210 100+
Note that in my previous post the problem statement is not the if statement "If (SelectedTD != this)" in the ClickTD function, but rather the two statements immediately following the if statement that are supposed to be executed when the condition is true.
Since 'Netscape' doesn't support attachEvent, it's hard to see how your code could work with it.
When you use attachEvent, this does not point to the element. Unless the cell is going to be assigned an additional handler, just assign the handler directly:

Expand|Select|Wrap|Line Numbers
  1. NewTD.onclick=ClickTD;
May 10 '08 #3
lxfc97
9
Hi,

Thanks very much, that worked.
I don't fully understand why yet, but I think I'll get it..

The same code that I posted does work in Netscape if you replace the attachEvent function with the addEventListener function, and if you replace SelectedTD.style.setAttribute("cssText","color:pur ple",0) with "SelectedTD.setAttribute("style","color:purple ").
I included only the IE specific statements in the test code that I posted--sorry for not indicating this.

Thanks again,
Dave
May 11 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John Max Skaller | last post by:
please reply to skaller@ozemail.com.au (I don't read this newsgroup, and the reply-to address is fake) For some time now -- over 5 years -- I have been using the interscript literate programming...
9
by: rez | last post by:
I find it rather frustrating that Netscape 4.x is "no longer supported:" http://help.netscape.com/products/client/communicator/reflib.html Same seems true with IE. How am I ever supposed to...
5
by: Dennis M. Marks | last post by:
Please look at page http://www.dcs-chico.com/~denmarks/amtrak.html I am trying to change the color of the first dropdown menu but everything that I have tried has no effect. If I put the style...
7
by: Steve | last post by:
I have a .NET application with a sql server database backend. Our client has been having problems lately with data being returned from the database with wrong data. We have error logging in our...
9
by: Abhishek | last post by:
How Does Functioning(Breaking in seperate block according to the logic using functions) a Programme effect the performance of the programme
35
by: Thierry Loiseau | last post by:
Hello all, and Happy end year 2005 ! Well, I would like to obtain a list of all JavaScript var statement, With "for...in" perharps ? That is bellow my recent test here, but the problem is...
10
by: News | last post by:
I have a page up trying to learn how to ID a browser and other info. http://wyght.com/warren/testPos.html here is the code <script type = "text/javascript"> var space = ", "; var name...
1
by: georgewbaba | last post by:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> </HEAD> <script type="text/javascript"> function addpath(obj ,vari){ ...
23
by: florian.loitsch | last post by:
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return...
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
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:
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
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,...

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.