Important alert: (current site time 7/15/2013 11:58:43 PM EDT)
 

VB icon

Yet another Table coloring

Email
Submitted on: 9/19/2000 7:51:34 AM
By: Jonathan Barton  
Level: Intermediate
User Rating: By 8 Users
Compatibility: ASP (Active Server Pages), HTML
Views: 28592
(About the author)
 
     This gives an alternating line color on tables, it also allows a realtime highlighting.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Yet another Table coloring
' Description:This gives an alternating line color on tables, it also allows a realtime highlighting.
' By: Jonathan Barton
'
' Inputs:All explained int he code
'
' Returns:All explained within the code
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=6329&lngWId=4'for details.'**************************************

<%
	'The const's are for the colors and the Flag is needed
	Const sPrimaryColor = "WHITE"
	Const sSecondaryColor = "YELLOW"
	Dim bColorFlag
	dim lCounter
	'This function does all the work for you.
	Function LineColor()
		bColorFlag = not bColorFlag
		If bColorFlag then
			LineColor = sPrimaryColor
		Else
			LineColor = sSecondaryColor
		End if
	End Function
%>
<SCRIPT language='VBScript'>
	Dim sRowOldColor
	Const sHighlightColor = "LIGHTBLUE"
	
	Sub Document_onclick()
		
		Dim sID
		
		'Need to show the parent of the element that was clicked on
		If Window.Event.srcElement.tagName = "TD" Then 
			sID = Window.Event.srcElement.ParentElement.id
			msgbox "ID = " & sID,,"This is the ID of the row."
		End If		
	End Sub
	Sub Document_onmouseover()
		If Window.Event.srcElement.tagName = "TD" Then 
			sRowOldColor = window.event.srcElement.ParentElement.bgcolor
			window.event.SrcElement.ParentElement.bgcolor=sHighlightColor
		End If
	End Sub
	
	Sub Document_onmouseout ()
		If window.event.srcElement.tagName = "TD" Then 
			window.event.srcElement.parentElement.bgcolor = sRowOldColor
		End If
	End Sub
</SCRIPT>
<HTML>
	<HEAD>
		<TITLE>
			Alternating Line Colors	
		</TITLE>
	</HEAD>
	<BODY>
		<CENTER>
			<P>
				<BR>
			</P>
			<TABLE width='80%' cellspacing='3' cellpadding='3' border='1'>
			<%
				for lCounter = 1 to 10
					Response.Write("<TR bgcolor='" & LineColor & "' id='" & lCounter & "'>" & vbCrLf)
					Response.Write("<TD><CENTER>" & lCounter & "</CENTER></TD>" & vbCrLf)
					Response.Write("</TR>" & vbCrLf)
				next
			%>
			</TABLE>
		</CENTER>
	</BODY>
</HTML>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

9/20/2000 11:07:30 AMTim2

While I couldn't use the code verbatim, it did make me think, and now I've got a killer new feature for my web apps!

Thanks!
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.