In article <3c**************************@posting.google.com >,
pi***********@yahoo.it enlightened us with...
I d like to use javascript ... at the moment it seems easier !
That's debatable. :)
I find it a lot easier in JSP personally.
what else I have to do is to show the months of the year up to the
corrent month. Can you help me in that too?
Tested in NN7 and IE6 only. No assumptions should be made for other
browsers - test in them if you want to check. Watch for word-wrappping.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title> New Document </title>
<script type="text/javascript" language="javascript">
function createYearSelect(parentElement, insertBeforeNode)
{
if (! document.getElementById || !document.createElement)
{
alert("Sorry, your browser doesn't support this operation.");
return;
}
var s = document.createElement("select");
s.id = "year";
s.name = "year";
parentElement.insertBefore(s, insertBeforeNode);
var today = new Date();
var thisYear = today.getYear();
if (thisYear < 2000) thisYear = thisYear + 1900;
for (var i=10; i>=0; i--)
{
var o = document.createElement("option");
o.name = "o"+i;
o.id = "o"+i;
o.value = (thisYear-i);
o.appendChild(document.createTextNode(thisYear-i));
s.appendChild(o);
}
// attach onchange event to select
if (s.attachEvent)
{
s.attachEvent("onchange",editMonths);
}
else if (s.addEventListener)
{
s.addEventListener("change",editMonths,false);
}
}
function editMonths()
{
var monthArray = new Array
("January","February","March","April","May","June" ,"July","August","Sept
ember","October","November","December");
// make months select depending on value of elementToCheck (year
select element)
// if it's already there, remove it and re-create
frm = document.forms["f1"];
elementToCheck = document.forms["f1"].elements["year"];
if (! document.getElementById || !document.createElement)
{
alert("Sorry, your browser doesn't support this operation.");
return;
}
if (document.getElementById("month"))
frm.removeChild(document.getElementById("month"));
// get the value of the first select
var val = elementToCheck.options[elementToCheck.selectedIndex].value;
// make month select element
var s = document.createElement("select");
s.name = "month";
s.id = "month";
frm.insertBefore(s, elementToCheck);
// fill in month select element with all months IF the selected year
is prior to this year
// OR with the months up to this month if the current year is
selected
var L;
var today = new Date();
var thisYear = today.getYear();
if (thisYear < 2000) thisYear = thisYear + 1900;
if (val == thisYear) L = today.getMonth();
else L = 11;
for (var i=0; i<=L; i++)
{
var o = document.createElement("option");
o.name = "o"+i;
o.id = "o"+i;
o.value = monthArray[i];
o.appendChild(document.createTextNode(monthArray[i]));
s.appendChild(o);
}
}
</script>
</head>
<body onLoad="createYearSelect(document.forms['f1'], document.forms
['f1'].elements['sub']);editMonths();">
<form id="f1" name="f1" action="" method="">
<br>
<input id="sub" name="sub" type="submit" value="submit">
</form>
</body>
</html>
--
--
~kaeli~
When you choke a smurf, what color does it turn?
http://www.ipwebdesign.net/wildAtHeart http://www.ipwebdesign.net/kaelisSpace