- Write A Cookie
function writeCookie(name, value) {
// Write out cookie of with 90 expiry date
var expdate = new Date()
expdate.setTime (expdate.getTime() + 90*(24 * 60 * 60 * 1000))
document.cookie = name+"="+value+";expires=" + expdate.toUTCString();
}
- Switch Source of window
window.location.replace('newFile.asp');
- Difference between two dates
startYear = "2001"
startMonth = "1"��� //---> ==FEBRUARY
startDay = "1"����� //---> == 1
endYear = "2002"
endMonth = "2"��� //---> ==MARCH
endDay = "26"����� //---> == 1
var startDate = new Date (startYear,startMonth,startDay)
var endDate = new Date (endYear,endMonth,endDay)
var startms = startDate.getTime();
var endms = endDate.getTime();
var difference = endms - startms;
var daysdifference = difference/1000/60/60/24;
- Conditional Operator
x = (expression) ? value1 : value2
x = value1 if expression true
x = value2 if expression false
- Form Select Box Values
- Child Windows
in the main window
var bReload = true;
xxx = window.open('aURL','aName')
window.xxx.hello
in the window thats opened
alert(this.opener.bReload)
function hello () {
alert ('hello')
}
- Random Number
If you need random floating-point numbers
in the range from A to B, use this code:
num is random, from A to B
num = A + (B-A)*Math.random()
- Switch Statement
switch sVarName {
case "selUniversityId":
frmApprovedCourses.sCourse.value = '';
break;
case "selCourseId":
frmApprovedCourses.sCourse.value = 'x';
break;
default:
break;
}
-