can get forecolor but not background color in Javascript

B

Bob

Hi,

When clicked into any cell of the table, i want to get the background color
of it. I can get the forecolor but not the bakground color (gives an empty
Alert, no error).
I think i can't change anything in the code-behind, so the error will be in
the javascript code ...

Thanks for your help
Bob

the aspx file:
-----------
<asp:Table ID="table1" runat="server"> </asp:Table>

<script language="javascript" type="text/javascript">
function tableclick(event)
{
forecl=window.event.srcElement.style.color
// this works
backcl=window.event.srcElement.style.background //
this not
alert(forecl)
alert(backcl)}
}

the code-behind:
----------------
'creattion of the cells in the table
Dim r As TableRow
Dim c(50, 20) As TableCell
For i = 0 To 50
r = New TableRow()
For j = 0 To 20
c(i, j) = New TableCell()
r.Cells.Add(c(i, j))
Next
Table1.Rows.Add(r)
Next
....
//e.g. the back/forecolor of cell 3,2:
c(3, 2).BackColor = System.Drawing.ColorTranslator.FromHtml("red")
c(3, 2).ForeColor = System.Drawing.ColorTranslator.FromHtml("yellow")
//c(3, 2).BackColor = Drawing.Color.Red
// tried also with this method
....
 
K

Klaus H. Probst

When clicked into any cell of the table, i want to get the background
color of it. I can get the forecolor but not the bakground color
(gives an empty Alert, no error).
I think i can't change anything in the code-behind, so the error will
be in the javascript code ...

It's not possible to read the default style properties of a DOM element.
They'll always return 'undefined' or whatever passes for that in
JavaScript.
 
B

Bob

Thanks, but then, how do you explain it works with the forecolor?
There must be a way to do the same with the background ...
 
R

Randy Webb

Bob said the following on 6/17/2006 4:59 AM:
Hi,

When clicked into any cell of the table, i want to get the background color
of it. I can get the forecolor but not the bakground color (gives an empty
Alert, no error).
I think i can't change anything in the code-behind, so the error will be in
the javascript code ...

backcl=window.event.srcElement.style.background //

window.event.srcElement.style.backgroundColor;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top