Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] [OT] JavaScript debugging - fresh eyes required



Hi,

I'm going cross-eyed through looking at these two javascript functions for
too long and need someone else's eyes to pick out the error here.

I have a huge javascript file for a site I'm currently developing. It works
fine on pretty much everything except Internet Exploder 7 (surprise,
surprise). It's been tested on Firefox, Safari and Opera, and I've heard
reports of it working on versions of IE prior to 7 but wouldn't actually
shake on that.

IE7 renders the page normally if I comment out these two functions. If I
leave them in, it halts with a javascript error "object expected" which is
not exactly helpful...

-----8<----- code snippet -----8<-----

function drawMonthSelect(id,class,current) {
	var i;
	var ret = "<select name='"+id+"' id='"+id+"' class='"+class+"'>";
	for ( i=1 ; i<=12 ; i++ ) {
		ret += "<option value='"+i+"'";
		if ( i == current ) ret += " selected='selected'";
		ret += ">"+months[i]+"</option>";
	}
	ret += "</select>";
	return ret;
}

function drawYearSelect(id,class,current) {
	var i;
	var ret = "<select name='"+id+"' id='"+id+"' class='"+class+"'>";
	for ( i=2008 ; i>=2008 ; i-- ) {
		ret += "<option value='"+i+"'";
		if ( i == current ) ret += " selected='selected'";
		ret += ">"+i+"</option>";
	}
	ret += "</select>";
	return ret;
}
-----8<----- code snippet -----8<-----

Note that the first "2008" in the for loop of the second function is just
"this year" generated programatically. This is in fact the output of a PHP
script that generates javascript which in turn generates HTML for direct
injection into the page's DOM. Twisted? Yeah. But it works (except in IE7).
Something tells me that this pie-chart is pretty accurate:

http://humor.beecy.net/geeks/web-design/web-design.gif

-- 
G. Stewart - gstewart@example.com

Reporter (to Mahatma Gandhi):
  "Mr. Gandhi, what do you think of Western civilisation?"
Gandhi:
  "I think it would be a good idea."


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links