473,386 Members | 1,715 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,386 software developers and data experts.

JS, DOM and tr... IE problems!

Hi folks!

I've got a problem with javascript and DOM.
I want to create a simple "intelligent" <table>, inside a data-form.
I'd like to do:
- Change color of any <tron onMouseOver DOM event;
- Check a checkbox on click on a <trand change <trbackground color.

Do you ever use phpMyAdmin? Well, the effect i'd like to get it's the
same that it's used in phpMyAdmin's tables. I try to look at phpMyAdmin
source code... But it's too difficult for me. ;-)

Let me show you my simple example file (in php format)...

- - - - - -

<html>
<head>
<title>test page</title>

<style type="text/css">
tr.even { background-color:#e5e5e5; }
tr.odd { background-color:#d5d5d5; }
tr.line_over { background-color:#ccffcc; }
tr.line_selected { background-color:#ffcc99; }
</style>

<script type="text/javascript">
<!--
function select_line(pForm,pObj,index)
{
var elem = pForm[pObj + '[]'];
elem[index].checked = !elem[index].checked;
}

function mouseOutRow(pForm,pRow,pObj,index,class)
{
var elem = pForm[pObj + '[]'];
if(elem[index].checked == true)
{
pRow.className='line_selected';
}
else
{
pRow.className=class;
}
}

// -->
</script>

</head>

<body>

<form name="myForm">
<table>
<tr>
<td>&nbsp;</td>
<td>#</td>
<td>value</td>
</tr>

<?
for($i=0;$i<10;$i++)
{
?>
<tr name="tr_line[]"
class="<? if($i%2==0) { print "even"; } else { print
"odd"; } ?>"
onClick="select_line(document.myForm,'px',<? print $i;
?>);"
onMouseOver="this.className='line_over';"
onMouseOut="mouseOutRow(document.myForm,this,'px', <?
print $i; ?>,'<?
if($i%2==0) { print "even"; } else { print "odd"; } ?>');">

<td width="25"><input type="checkbox" name="px[]" /></td>
<td width="25"><? print $i+1; ?></td>
<td>test row</td>
</tr>
<?
}
?>
</table>
</form>
</body>
</html>

- - - - - -

With Firefox it works fine; but it doesn't work with Internet Explorer!
IE seems to don't use javascript functions in DOM events of <trtag: I
try to set only .style.background-color in "onMouseOut" and other
events... It work!

I don't understand why this... Maybe I can't use these DOM events on
<trtag? Or I mistake something?

Please, try to help me if you can!
In alternative, do you know another way to do my tables?
Thanks a lot, folks!

Nov 18 '06 #1
7 2557
I vaguely recall from some past experience that IE can't properly parse
tables into the DOM tree unless there's a <tbodyelement - that is,
<trshould be child of <tbodynot directly of <table>:

<table>
<tbody>
<tr><td>stuff here</td></tr>
</tbody>
</table>

Of course this has nothing to do with any standards since the W3C says
that TR can come below either <tableor <tbody>, but you know IE's
relationship to standards... Try that and see if it works for you.

-David

Nov 18 '06 #2

Hi David,

Thank you for your answer!
I'm trying to add <tbodytag... But nothing change. :-(

Any other ideas?

ps.. Of course David: I know IE's standard problems... It always does
not like my css code! Eheheh....

Nov 19 '06 #3
deste wrote:
Hi folks!

I've got a problem with javascript and DOM.
I want to create a simple "intelligent" <table>, inside a data-form.
I'd like to do:
- Change color of any <tron onMouseOver DOM event;
Capitalisation is often used in HTML markup, however I find it
misleading. In script you must write onmouseover, so better to use the
same in the HTML. Just a personal preference of course... :-)
- Check a checkbox on click on a <trand change <trbackground color.

Do you ever use phpMyAdmin? Well, the effect i'd like to get it's the
same that it's used in phpMyAdmin's tables. I try to look at phpMyAdmin
source code... But it's too difficult for me. ;-)

Let me show you my simple example file (in php format)...
Don't post server code, keep that for a php group. Post what your
browser actually receives, once you sort that out, how you get it there
is up to you.

[...]
<script type="text/javascript">
<!--
Don't use HTML comment delimiters inside script tags, they are useless
and likely to cause problems (though not in this case).

[...]
>
With Firefox it works fine; but it doesn't work with Internet Explorer!
IE seems to don't use javascript functions in DOM events of <trtag:
A notion that is easily disproved:

<table><tr onmouseover="alert('hey');"><td>blah</table>
I
try to set only .style.background-color in "onMouseOut" and other
You should be setting: style.backgroundColor. When using CSS
properties in javascript, hyphenated names must be converted to
"camelCase".

events... It work!
So it does work? I'm confused.

>
I don't understand why this... Maybe I can't use these DOM events on
<trtag? Or I mistake something?
Yes, you can.
>
Please, try to help me if you can!
If you post what your browser is actually getting (e.g. using view
source or the generated source), then more help can be offered.
Othewise you are asking someone to load your PHP on a server and
deliver it to a browser to debug, or be a sufficiently good PHP
developer that they can see the bugs in the code. Count me out!!!!
:-)

In alternative, do you know another way to do my tables?
I think your approach using CSS classes is the best one. While the
:hover pseudo-class is supported by a wide variety of browsers, it
isn't supported by IE<7, so script is your only option:

<head>
<title>tr play</title>
<style type="text/css">
.blue {background-color: #ddddff;}
.pink {background-color: #ffdddd;}
</style>
</head>
<table>
<tr onmouseover="this.className='blue';"
onmouseout="this.className='pink';">
<td>blah</td>
</tr>
</table>

--
Rob

Nov 19 '06 #4

Thank you very much Rob for your suggestions!
And excuse me for my mistakes (php code etc...) ;-)

I try to apply some changes...
Don't ask me why, but now it works! :pPpp
I'll try to understand later why before my script didn't work and now
yes... It seems to be the same... (??).

If you are interested, this is the code...

----------

<html>
<head>
<title>test page</title>

<style type="text/css">
tr.even { background-color:#e5e5e5; }
tr.odd { background-color:#d5d5d5; }
tr.line_over { background-color:#ccffcc; }
tr.line_selected { background-color:#ffcc99; }
</style>

<script type="text/javascript">
function select_line(pForm,pObj,index)
{
var elem = pForm[pObj + '[]'];
elem[index].checked = !elem[index].checked;
}
function mouse_over(pRow) { pRow.className='line_over'; }
function mouse_out(pForm,pRow,pObj,index,css_class)
{
var elem = pForm[pObj + '[]'];
if(elem[index].checked == true)
{
pRow.className='line_selected';
}
else
{
pRow.className=css_class;
}
}
</script>

</head>

<body>
<form name="myForm">
<table>
<tbody>
<tr name="tr_line[]" class="even"
onclick="select_line(document.myForm,'px',0);"
onmouseover="mouse_over(this);"

onmouseout="mouse_out(document.myForm,this,'px',0, 'even');">
<td><input type="checkbox" name="px[]"
onclick="select_line(document.myForm,'px',0);" /></td>
<td>first line bla bla bla...</td>
</tr>

<tr name="tr_line[]" class="odd"
onclick="select_line(document.myForm,'px',1);"
onmouseover="mouse_over(this);"

onmouseout="mouse_out(document.myForm,this,'px',1, 'odd');">
<td><input type="checkbox" name="px[]"
onclick="select_line(document.myForm,'px',1);" /></td>
<td>second line bla bla bla...</td>
</tr>

</tbody>
</table>
</form>

</body>
</html>

----------

Bye bye, and thanks for your help. :-)

Nov 19 '06 #5
Capitalisation is often used in HTML markup, however I find it
misleading. In script you must write onmouseover, so better to use the
same in the HTML. Just a personal preference of course... :-)
It is not just personal preference. For your document to validate under
XHTML, attribute names must be lowercase.
> <script type="text/javascript">
<!--

Don't use HTML comment delimiters inside script tags, they are useless
and likely to cause problems (though not in this case).
A leftover from *really* old browsers that didn't understand script
tags. Now, what about <![CDATA[ ... script code ]]? :D

--
Bas Cost Budde
Holland
www.heuveltop.nl/BasCB/msac_index.html
Nov 19 '06 #6

Ohhh... I understand why my first code don't works in IE, folks!! :-))
If you are interesting, let me explain you what is the real problem
(take a look... Can will be usefull to know it...)

This code DON'T work in IE...
----------
<html>
<head>
<script type="text/javascript">
<!--
function test(class) { alert(class); }
// -->
</script>
</head>
<body>
<a href="#" onclick="test('don\'t work in IE !');">click here to
test...</a>
</body>
</html>
----------

....But this works fine:
----------
<html>
<head>
<script type="text/javascript">
<!--
function test(something_different_class) {
alert(something_different_class); }
// -->
</script>
</head>
<body>
<a href="#" onclick="test('this code works in IE !');">click here
to test...</a>
</body>
</html>
----------

Ouch! F*ck!
Don't ask me why... But in I.E. 6 (I don't know in < or 6 versions),
you can't use "class" as variable's name in a function! :-)

Thanks a lot to David, Rob and Bas for their answers!
PS about comment tags...
<script>
<!--
[...]
// -->
</script>
Comment tags, as Bas say, must be used for *very* old browser that
doesn't support Javascript... But is better use it also for new devices
different from computer (like cellular phones...) that can don't
understand javascript and for web crawler (like GoogleBot and others):
they don't need to read our javascript code.
See u!

--- EOF ---

Nov 19 '06 #7
Don't ask me why... But in I.E. 6 (I don't know in < or 6 versions),
you can't use "class" as variable's name in a function! :-)
<slaps foreheadOf course, class is a reserved keyword in JS, so you
shouldn't use it as a variable name.

Nov 19 '06 #8

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

Similar topics

0
by: Jerome Lefebvre | last post by:
Hello, Hope this will interest a few. I been working with a friend on the problems given out during the "International Collegiate Programming Contest" (ICPC) http://icpc.baylor.edu/icpc/ ....
14
by: Jim Hubbard | last post by:
Are you up to speed on the difficulties in using the 1.1 .Net framework? Not if you are unaware of the 1,596 issues listed at KBAlertz (http://www.kbalertz.com/technology_3.aspx). If you are...
1
by: 3f | last post by:
Hello; We have made a web application that people can download from our web site and installed on: Windows XP Windows 2000 Professional Windows 2003 Server Windows 2000 Server
5
by: Corky | last post by:
This works: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS INNER JOIN PROBLEMS ON PROBLEM_OBJECTS.PROBLEM_ID = PROBLEMS.PROBLEM_ID WHERE INTEGER(DAYS(CURRENT DATE) -...
2
by: Ellen Graves | last post by:
I am having a lot of problems with DB2 8.3.1 on RH Linux AS2.1. Installing and running stored procedures is problematic. Stored procedures I have used for years on V7 on WinNT are now failing...
19
by: Jim | last post by:
I have spent the past few weeks designing a database for my company. The problem is I have started running into what I believe are stack overflow problems. There are two tab controls on the form...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
0
by: Sergistm | last post by:
Hello World, :D I have a problem that it is making me crazy, I hope you can help me. I'm trying to execute a .exe file with the Procces.Start, and there is no problem when the file is on my...
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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.