Blog Archives

lastChild is null in FireFox works in IE invalid nodeType javascript c# asp .net

This issue alluded me at first as it works in IE but not in FF. See code below.

//pass in table, last cell number and style to apply to it. call this on hover and blur for cell highlight effects. alternatively you can determine last cell number as well and this function could be rewritten to work solely for the purpose of modifying specific cells rather than last cell
function ChangeTableCellStyle(tableid,cellnumber,mystyle) {
if (document.getElementById)
var selectedElement = document.getElementById(tableid);
selectedElement.className = style;
//change style on end cell by drilling into table. this will become deprecated by css3.
if (selectedElement.tagName.toLowerCase()=="table")

var tbody = selectedElement.lastChild;
if (tbody!=null)
var tr = tbody.lastChild;
if (tbody !=null)
var tr = tbody.lastChild; //BUGGED IN FF!

//nodetype should be 1 for element type. in FF it is 3. see reference link at bottom for list of types.
if (tr.nodeType!=1) {
tr[cellnumber].className+= ' ' + mystyle;
} else {
tr.lastChild.className+=' ' + mystyle;




//example usage
ChangeTableCellStyle("table1",3,"cellend"); //will append the class cellend to the last cell in table1 if table1 only has 4 cells per row

In you’re interested in reviewing other approaches to styling your table cells, see my similar article here.


Serialize C# object to JSON JavaScriptSerializer .Net

//declare data you want to send as an object type
public class MyType {
//may simply contain properties mapping to your database rows or be more complex objects
//use [Serializable] attributes to mark props or methods as non-serialized
public void Page_Load(object sender, EventArgs e) {
MyType o1 = new MyType {p1="",p2=""};


Response.Write("<br /><br />");

MyType o2 = new MyType {p1="",p2=""};
List<MyType> olist = new List<MyType> {o1, o2};


public string JSONSerialize(MyType o) {
System.Web.Script.Serialization.JavaScriptSerializer sz = 
         new System.Web.Script.Serialization.JavaScriptSerializer();
return sz.Serialize(o);

//additional signature to handle lists of object
public string JSONSerialize(List<MyType> o) {
System.Web.Script.Serialization.JavaScriptSerializer sz = 
         new System.Web.Script.Serialization.JavaScriptSerializer();
return sz.Serialize(o);

MS Blogs,,
C# Cross-Site Page Access,
PHP Cross-Site Page Access,
JS Eval string to JSON Object,

asp .net c# luhn algorithm validation mod10 with realtime clientside Javascript

Read the rest of this entry

Simple Javascript CountDown timer and Page Redirect in HTML

<title>SiteName (test)</title>
<script type="text/javascript">
var ss = 10;
function countdown() {
ss = ss-1;
if (ss<0) {
else {
window.setTimeout("countdown()", 1000);
<body onload="countdown()">
<table width="100%" height="600px" style="text-align:center;">
<tr><td valign="center"><h3>Redirecting to <a href=""></a> (<span id="countdown" style="color:green;">10</span>)</h3></td></tr>

Get Current URL in Javascript

JS (JQuery):

$(document).ready(function() {

JS (standard):

function CurrentURL() {
    var currenturl = window.location.pathname;
return currenturl;