I am trying to write a CustomValidator for ASP.NET and am getting strange behavior with my javascript.
This WORKS:This DOES NOTCode:var myString = "2006-07"; var mySplitResult = myString.split("-"); var firstyear = mySplitResult[0]; var firstdecade = Right(firstyear,2); var secondyear = mySplitResult[1]; document.write("The Year Spread is " + myString); document.write("<br /><br />The first year is [" + firstyear + "]"); document.write("<br />The first decade is [" + firstdecade + "]"); document.write("<br />The second year is [" + secondyear + "]"); document.write("<br /><br />[first decade] + 1 = second year: " + (parseInt(firstdecade) + 1 == parseInt(secondyear))) function Left(str, n) { if (n <= 0) return ""; else if (n > String(str).length) return str; else return String(str).substring(0, n); } function Right(str, n) { if (n <= 0) return ""; else if (n > String(str).length) return str; else { var iLen = String(str).length; return String(str).substring(iLen, iLen - n); } }Code:var myString = "2007-08"; var mySplitResult = myString.split("-"); var firstyear = mySplitResult[0]; var firstdecade = Right(firstyear,2); var secondyear = mySplitResult[1]; document.write("The Year Spread is " + myString); document.write("<br /><br />The first year is [" + firstyear + "]"); document.write("<br />The first decade is [" + firstdecade + "]"); document.write("<br />The second year is [" + secondyear + "]"); document.write("<br /><br />[first decade] + 1 = second year: " + (parseInt(firstdecade) + 1 == parseInt(secondyear))) function Left(str, n) { if (n <= 0) return ""; else if (n > String(str).length) return str; else return String(str).substring(0, n); } function Right(str, n) { if (n <= 0) return ""; else if (n > String(str).length) return str; else { var iLen = String(str).length; return String(str).substring(iLen, iLen - n); } }
Why would 06+1=07 return TRUE
and 07+1=08 return FALSE


Reply With Quote
Bookmarks