Hi:
I am trying to write a javascript using onLoad event on Select object. i want to set the values of months based on following logic
If (current month > month selected)
use current year+1
else
use current year
and then replace current month values with new values. so for example if we select jan, then jan value should be
01/01/2002 and if we select October then value should be
10/01/2001.
i tried using onChange,and onFocus event but want to do with onLoad event so that all the values are set when the screen loads.
thanks in advance,
vaks
Here is what i have tried so far:<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; ">
<meta name="Author"
content="All rights reserved.">
<meta name="GENERATOR" content="vi">
<title>Registration: Class Query</title>
<SCRIPT LANGUAGE="JavaScript">
function populate(myForm,myCnt) {
var dateNow = new Date();
var yearNow = dateNow.getFullYear();
var monthNow = dateNow.getMonth();
if (monthNow > myCnt) {
newYear = yearNow+1;
alert(newYear);
}
else {
newYear = yearNow;
}
myval= document.f1.field_value.options[myCnt].value;
if (myval.length != 10) {
document.f1.field_value.options[myCnt].value = (document.f1.field_value.options[myCnt].value+newYear);
}
alert(document.f1.field_value.options[myCnt].value);
document.f1.field_value.options[myCnt].selected=true;
}
</script>
</head>
<body bgcolor="#FFFFFF">
<form name=f1>
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%"><hr>
<h3 align="center">Course Query</h3>
<form>
<table border="0" cellpadding="4" cellspacing="0"
width="100%">
<tr>
<td><b>Select Date:</b></td>
<td><select name="field_value" onFocus="populate(this.form,this.selectedIndex);" onChange="populate(this.form,this.selectedIndex);" size="1">
<option value="01/01">Jan</option>
<option value="02/01">Feb</option>
<option value="03/01">Mar</option>
<option value="04/01">Apr</option>
<option value="05/01">May</option>
<option value="06/01">Jun</option>
<option value="07/01">Jul</option>
<option value="08/01">Aug</option>
<option value="09/01">Sep</option>
<option value="10/01">Oct</option>
<option value="11/01">Nov</option>
<option value="12/01">Dec</option>
</select>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</form>
</body>
</html>
I am trying to write a javascript using onLoad event on Select object. i want to set the values of months based on following logic
If (current month > month selected)
use current year+1
else
use current year
and then replace current month values with new values. so for example if we select jan, then jan value should be
01/01/2002 and if we select October then value should be
10/01/2001.
i tried using onChange,and onFocus event but want to do with onLoad event so that all the values are set when the screen loads.
thanks in advance,
vaks
Here is what i have tried so far:<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; ">
<meta name="Author"
content="All rights reserved.">
<meta name="GENERATOR" content="vi">
<title>Registration: Class Query</title>
<SCRIPT LANGUAGE="JavaScript">
function populate(myForm,myCnt) {
var dateNow = new Date();
var yearNow = dateNow.getFullYear();
var monthNow = dateNow.getMonth();
if (monthNow > myCnt) {
newYear = yearNow+1;
alert(newYear);
}
else {
newYear = yearNow;
}
myval= document.f1.field_value.options[myCnt].value;
if (myval.length != 10) {
document.f1.field_value.options[myCnt].value = (document.f1.field_value.options[myCnt].value+newYear);
}
alert(document.f1.field_value.options[myCnt].value);
document.f1.field_value.options[myCnt].selected=true;
}
</script>
</head>
<body bgcolor="#FFFFFF">
<form name=f1>
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tr>
<td valign="top" width="100%"><hr>
<h3 align="center">Course Query</h3>
<form>
<table border="0" cellpadding="4" cellspacing="0"
width="100%">
<tr>
<td><b>Select Date:</b></td>
<td><select name="field_value" onFocus="populate(this.form,this.selectedIndex);" onChange="populate(this.form,this.selectedIndex);" size="1">
<option value="01/01">Jan</option>
<option value="02/01">Feb</option>
<option value="03/01">Mar</option>
<option value="04/01">Apr</option>
<option value="05/01">May</option>
<option value="06/01">Jun</option>
<option value="07/01">Jul</option>
<option value="08/01">Aug</option>
<option value="09/01">Sep</option>
<option value="10/01">Oct</option>
<option value="11/01">Nov</option>
<option value="12/01">Dec</option>
</select>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</form>
</body>
</html>