473,604 Members | 2,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dhtml style in IE internet explorer

When I wrote the following code to create a dynamic table with styles
associated with each row, it worked in Firefox. But when this was tried
in IE, the result was a table with no styles that were displayed. Could
someone explain to me how a dynamic table should be created (in IE)?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<link rel="stylesheet " href="css/1.css" type="text/css" />
</head>

<body>

<table id="gst">
<tr>
<td>Rent</td>
<td>BR</td>
<td>Name</td>

<td>Street</td>
<td>Date</td>
</tr>

<tr class="odd" onmouseover = 'this.className ="over"'
onmouseout='thi s.className="od d"' onclick='openWi ndow(1,lease_li st)'>
<td>RR</td>
<td>RR</td>
<td>RR</td>
<td>RR</td>
<td>RR</td>

</tr>

</table>

<script type="text/javascript">
function showTable(){

table = document.getEle mentById('gst') ;
var x=table.insertR ow(1);
var y=x.insertCell( 0);
var z=x.insertCell( 1);
x.setAttribute( 'onclick','open Window('+' '+'1,lease_list )');
cl="odd";
x.setAttribute( 'class',cl);
x.setAttribute( 'onmouseover',' this.className= "over"');
x.setAttribute( 'onmouseout','t his.className=" '+cl+'"');
y.innerHTML="NE W CELL1";
z.innerHTML="NE W CELL2";
}

showTable();

</script>

</body>

</html>

Apr 2 '06 #1
3 1803
Mahmoud wrote :
When I wrote the following code to create a dynamic table with styles
associated with each row, it worked in Firefox. But when this was tried
in IE, the result was a table with no styles that were displayed. Could
someone explain to me how a dynamic table should be created (in IE)?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<link rel="stylesheet " href="css/1.css" type="text/css" />
</head>

<body>

<table id="gst">
<tr>
<td>Rent</td>
<td>BR</td>
<td>Name</td>

<td>Street</td>
<td>Date</td>
</tr>

<tr class="odd" onmouseover = 'this.className ="over"'
onmouseout='thi s.className="od d"' onclick='openWi ndow(1,lease_li st)'>
<td>RR</td>
<td>RR</td>
<td>RR</td>
<td>RR</td>
<td>RR</td>

</tr>

</table>

<script type="text/javascript">
function showTable(){

table = document.getEle mentById('gst') ;
Right here, you are creating a second table which will have the same id
attribute value as the first one. Id attribute value must be
document-unique.

http://www.w3.org/TR/html401/struct/global.html#adef-id

You also have declare table as a global variable... when it doesn't seem
necessary to do so.

var x=table.insertR ow(1);
You need to create a tbody first and append it to the table first; MSIE
requires this in order to be able to insert row to it.
var y=x.insertCell( 0);
var z=x.insertCell( 1);
x.setAttribute( 'onclick','open Window('+' '+'1,lease_list )');
This won't work.

x.onclick = new Function ("evt", "openWindow ('1, lease_list');") ;
cl="odd";
x.setAttribute( 'class',cl);
You should avoid resorting to setAttribute() because IE has a number of
flaws, bugs on this method. And you can avoid declaring the cl variable.

x.className = "odd";
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-95362176
x.setAttribute( 'onmouseover',' this.className= "over"');
x.onmouseover = new Function("evt", "this.class Name = 'over';");
x.setAttribute( 'onmouseout','t his.className=" '+cl+'"');
x.onmouseover = new Function("evt", "this.class Name = 'odd';");
y.innerHTML="NE W CELL1";
y.appendChild(d ocument.createT extNode("NEW CELL1"));
z.innerHTML="NE W CELL2";
z.appendChild(d ocument.createT extNode("NEW CELL2"));
}

showTable();
You should call the showTable() only and only when the document has been
fulled loaded and parsed and once the DOM tree has been built: this is
for best results (speed, memory management, avoid crashing on some other
browsers, etc.). It may work while loading the document but I would
still discourage such coding practice.

</script>

</body>

</html>


Not tested.

Gérard
--
remove blah to email me
Apr 2 '06 #2
Mahmoud wrote:
When I wrote the following code to create a dynamic table with styles
associated with each row, it worked in Firefox. But when this was tried
in IE, the result was a table with no styles that were displayed. Could
someone explain to me how a dynamic table should be created (in IE)?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
IE does not support XHTML. Use HTML 4.01 Strict, that suffices here, and
makes using possibility of inner_HTML_ reasonable in the first place.
<head>
<link rel="stylesheet " href="css/1.css" type="text/css" />
In XHTML, as an XML application, the stylesheet must be referenced
in an XML Process Instruction before the DOCTYPE declaration:

<?xml-stylesheet type="text/css" href="css/1.css"?>

It only worked with `link' because the XHTML was rendered as error-corrected
HTML as you served it as text/html. Serve XHTML as application/xhtml+xml
(then you will recognize that IE does not support it.)
</head>

<body>

<table id="gst">
[...]
<tr class="odd" onmouseover = 'this.className ="over"'
onmouseout='thi s.className="od d"' onclick='openWi ndow(1,lease_li st)'>
Users without client-side scripting will not be able to use the table as
intended. Use <a href="..." onclick="...; return false;">...</a> instead.
[...]
<script type="text/javascript">
function showTable(){

table = document.getEle mentById('gst') ;
Of course, you are _not_ creating a new table with the same ID here.

But since you do not declare the `table' identifier, you try to add a
globally available property. That may not be possible in IE, because
there is an object before the Global Object in the scope chain that
does not allow adding properties with certain names. Try

var table = ...;

instead.
var x=table.insertR ow(1);
var y=x.insertCell( 0);
var z=x.insertCell( 1);
Missing feature tests.
<URL:http://pointedears.de/scripts/test/whatami#inferen ce>
x.setAttribute( 'onclick','open Window('+' '+'1,lease_list )');
There is no point in this concatenation.

x.setAttribute( 'onclick', 'openWindow(1, lease_list)');

But setAttribute() has buggy implementations , so you should avoid it.
Use

x.onclick = function()
{
openWindow(1, lease_list);
};

or (IE4-proprietary)

x.attachEvent(
'onclick',
function()
{
openWindow(1, lease_list);
});

or (standards compliant)

x.addEventListe ner(
'click',
function()
{
openWindow(1, lease_list);
},
false);

For maximum compatibility, you should combine those approaches.
See also <URL:http://pointedears.de/scripts/dhtml.js>.
cl="odd";
var cl = "odd";
x.setAttribute( 'class',cl);
x.className = cl;
x.setAttribute( 'onmouseover',' this.className= "over"');
x.setAttribute( 'onmouseout','t his.className=" '+cl+'"');
See above.
y.innerHTML="NE W CELL1";
z.innerHTML="NE W CELL2";
Avoid `innerHTML' if the new content is only a text node.

function isMethod(a)
{
var t;
return (a && ((t = typeof a) == "function" || t == "object"))) ;
}

if (isMethod(y.app endChild)
&& isMethod(z.appe ndChild)
&& isMethod(docume nt.createTextNo de))
{
y.appendChild(d ocument.createT extNode("NEW CELL1"));
z.appendChild(d ocument.createT extNode("NEW CELL2"));
}
else if (typeof y.innerText != "undefined"
&& typeof z.innerText != "undefined" )
{
y.innerText = "NEW CELL1";
z.innerText = "NEW CELL2";
}
else if (typeof y.innerHTML != "undefined"
&& typeof z.innerHTML != "undefined" )
{
y.innerHTML = "NEW CELL1";
z.innerHTML = "NEW CELL2";
}

Another possibility for a combining wrapper method here.
}

showTable();

PointedEars
Apr 2 '06 #3
Gérard Talbot wrote:
Mahmoud wrote :
When I wrote the following code to create a dynamic table with styles
associated with each row, it worked in Firefox. But when this was tried
in IE, the result was a table with no styles that were displayed. Could
someone explain to me how a dynamic table should be created (in IE)?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
There is little to recommend XHTML. There is certainly nothing in the
posted code to suggest it is necessary, use HTML unless you have a really
good reason for using XHTML.
<head>
<link rel="stylesheet " href="css/1.css" type="text/css" />
When styles are part of the problem, you need to include a minimal style
element so the code works as posted.

Your markup is invalid without a title element.
</head>

<body>

<table id="gst">
[...]
</table>

<script type="text/javascript">
function showTable(){

table = document.getEle mentById('gst') ;

Right here, you are creating a second table which will have the same id
attribute value as the first one.


Not at all. 'table' is a reference to the existing table with id='gst'.
[...] You also have declare table as a global variable... when it doesn't seem
necessary to do so.

var x=table.insertR ow(1);

You need to create a tbody first and append it to the table first; MSIE
requires this in order to be able to insert row to it.


A tbody is created when the HTML for the table is parsed, so the fact that
the browser has already parsed the HTML for the subject table means it has
a tbody.

inesertRow() is a method of the table interface and is intended to be used
exactly as the OP has used it, that is:

tableElementRef erence.insertRo w(index)

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-39872903>

var y=x.insertCell( 0);
var z=x.insertCell( 1);
x.setAttribute( 'onclick','open Window('+' '+'1,lease_list )');

This won't work.


Yup. Also, to the OP, where is 'lease_list' defined?

cl="odd";
x.setAttribute( 'class',cl);

You should avoid resorting to setAttribute() because IE has a number of
flaws, bugs on this method. And you can avoid declaring the cl variable.


I'll add that the OP should also have included a style element with the
required classes defined. Nothing worse than having work out what is
broken because of errors and what has simply been omitted.

x.className = "odd";
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-95362176
x.setAttribute( 'onmouseover',' this.className= "over"');

x.onmouseover = new Function("evt", "this.class Name = 'over';");


Hmmm. Calling the Function object as a constructor is not liked and should
probably be avoided where possible. There seems little point in passing
'evt'. Try:

x.onmouseover = function(){this .className = 'over';};
Looking at the event might be useful if the OP had a generic function that
used the event type to work out whether to highlight the row or return it
to odd/even class, but that doesn't seem to be happening here.

x.setAttribute( 'onmouseout','t his.className=" '+cl+'"');


Where was 'cl' defined? Is it a variable or string value?

[...]
}

showTable();

You should call the showTable() only and only when the document has been
fulled loaded and parsed and once the DOM tree has been built: this is
for best results (speed, memory management, avoid crashing on some other
browsers, etc.). It may work while loading the document but I would
still discourage such coding practice.


Maybe, but then users will see the page load and render, then the new
elements get added.

Which browsers have difficulty with elements being added while the page loads?

[...]

--
Rob
Apr 2 '06 #4

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

Similar topics

6
1992
by: viator | last post by:
Hello everybody. I am a student doing my masters in Comp. Sci. Will some explain to me why it seems completely two worlds when taking about DHTML in NN and IE. Is there any way to write truly portable webpages using DHTML ofcourse.
1
1599
by: Web Master | last post by:
The following works in Internet Explorer 6 and Opera, but not Netscape 7.1. Is there any way to make this work in all three browsers? <html> <head> <title>Menu</title> </head> <body> <div style="position: absolute; left: 250; top: 172; width: 62; height: 115"
3
1920
by: Chris Leonard | last post by:
Hi. I've copied some code from a book which will enable me to make a layer around a page, my aim is to do something a little more complex but this I thought would get me started. Anyway, I've run into a problem before I even start! The script works OK, it runs the image in from the left hand side quite nicely, great. Problem I have it always scrolls up to the top of the page, when the link I click maybe 2 or 3 screens below (does that...
14
1863
by: Dafydd | last post by:
I have the following Script in my web page reduce to two pages. <script> function details() { document.getElementById('details').style.visibility='visible'; document.getElementById('capabilities').style.visibility='hidden'; } function capabilities() {
8
2692
by: Brett | last post by:
Both make use of DIV tags or layers. What are the main differences between DHTML and style sheets? Also, what type of problems might an author experience in the way of incompatibilities? For example, by: - browser type - OS - firewall settings - Antivirus settings - network administrator setting restrictions
2
1472
by: A. Nonymous | last post by:
I am trying to write a function that will centre a DIV-layer into the middle of the web browser screen. This is only for Internet Explorer. I keep getting and Invalid Argument error whenever I call the function (in the line oRef.style.left = ...). I am brain dead! What's wrong with my code? TIA.. function CentreOnScreen(LayerID) { var oRef = eval('document.all.'+ LayerID); //alert(oRef +', '+ LayerID);
0
7178
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along the way. First, deep linking is not something that a completely AJAX web site should be able to do by it's very nature of everything being on one page basically. So how can a person deep link to something that is on one page? This question...
10
6749
by: cjparis | last post by:
Hello everyone. If anyone can give me a hand I would be gratefull Am doing a site which requires a moving element and have used DHTML to do it. Have a simple Browser detect script to sort IE from Netscape. IE is ok but the Netscape browser including Firefox and Safari are not working now. Not sure why. The idea is that when you mouseover the arrows the gallery div moves to left and right. I have changed the script and now the image...
3
1775
by: Berlin Brown | last post by:
http://www.w3schools.com/htmldom/prop_frame_scrolling.asp I want to be able to get this example working with Internet explorer. it works fine in firefox. Does anyone have an idea how to resolve this bug. 'Basically, I want to be able to change the properties of a frame after the properties have been defined. E.g. turn scrolling from "no" to "yes"
9
5303
by: ninhovid | last post by:
Hi... i'm new at dhtml, and i want to use it in help windows (instead of window.open() of javascript)... i'm done it... but it works only in internet explorer.. in firefox 2 and 3 it opens the dhtml modal window but in the background of my main page... what do i have to correct so it opens up in front as it does in internet explorer? i'm using c# and ajax... it's an asp.net app... in masterpage i have this: <link rel="stylesheet"...
0
7929
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8419
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8065
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
5441
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3907
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3955
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2434
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
1526
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1266
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.