Home All Groups Group Topic Archive Search About

can get forecolor but not background color in Javascript

Author
17 Jun 2006 8:59 AM
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
....

Author
17 Jun 2006 9:32 AM
Klaus H. Probst
"Bob" <s**@sdvsd.dc> wrote in
news:udHT3xekGHA.1204@TK2MSFTNGP02.phx.gbl:

> 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.


--
Klaus H. Probst, MVP
    http://www.simulplex.net/
Author
17 Jun 2006 10:56 AM
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 ...

Show quoteHide quote
"Klaus H. Probst" <usenet***@simulplex.net> wrote in message
news:Xns97E519D47DEE945F9BC4070F84482B8A8@207.46.248.16...
> "Bob" <s**@sdvsd.dc> wrote in
> news:udHT3xekGHA.1204@TK2MSFTNGP02.phx.gbl:
>
> > 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.
>
>
> --
> Klaus H. Probst, MVP
>     http://www.simulplex.net/
>
Author
17 Jun 2006 11:33 AM
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 ...

<snip>

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

window.event.srcElement.style.backgroundColor;

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Author
18 Jun 2006 9:41 AM
André
thanks

Show quoteHide quote
"Randy Webb" <HikksNotAtH***@aol.com> wrote in message
news:DJudnXT4kNAPdQ7ZnZ2dnUVZ_qSdnZ2d@comcast.com...
> 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 ...
>
> <snip>
>
> > backcl=window.event.srcElement.style.background                       //
>
> window.event.srcElement.style.backgroundColor;
>
> --
> Randy
> comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
> Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/