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

can get forecolor but not background color in Javascript

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
....
Jun 17 '06 #1
4 1805
"Bob" <sd*@sdvsd.dc> wrote in
news:ud**************@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/

Jun 17 '06 #2
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 ...

"Klaus H. Probst" <us*******@simulplex.net> wrote in message
news:Xn**********************************@207.46.2 48.16...
"Bob" <sd*@sdvsd.dc> wrote in
news:ud**************@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/

Jun 17 '06 #3
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/
Jun 17 '06 #4
thanks

"Randy Webb" <Hi************@aol.com> wrote in message
news:DJ******************************@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/
Jun 18 '06 #5

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

Similar topics

4
by: erik | last post by:
Is it posssible to inherit the previous pages (parent pages) background image? Is there a script out there I could look at? Thanks
4
by: Nathan Given | last post by:
Hello All, I am trying to randomly change the background image of my home page but I can't seem to figure it out. Here is a snippet of my css .... BODY {background:transparent...
11
by: Konrad Den Ende | last post by:
I have a function returning a string but the problem is that the color of it is blue which suits me well for some pages but not for others. Is it possible to "feel" what the color of the background...
3
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
4
by: rkbnair | last post by:
I have an image placed on an aspx page. <img id="xyz" onMouseOver="abc()" src="c:\temp\ijk.jpg"> My Text to Display How can I change the forecolor of the text 'My Text to display' in function...
4
by: Tom John | last post by:
Hi I have a ListView that i want to be able to modify the color of particular items depending on whether the value of the item they are about to be replaced with is higher, lower or the same: ...
5
by: Bernie Yaeger | last post by:
When you use xp styles Application.EnableVisualStyles() Application.DoEvents() and you change a control's flat style to 'system', you then are not able to set the control's forecolor,...
4
by: Stephen | last post by:
greeting folks I would like to change the foreground color for a disabled textbox from the dimmed gray to something else that is easlier readable. I can change the background using the...
7
by: moondaddy | last post by:
in asp.net 2.0, i have a link buttonand want to change the forecolor in a mouse over event. how can I do this? -- moondaddy@noemail.noemail
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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...

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.