Hi All,
I do not typically program using javascript however I have built a form that requires your date of birth being entered where I have used select boxes. When the user selects a month the script will work out how many days in that month and then populate the days selectbox and then on to the year.
It was working fine when I had it inside the same page as the form but know I have moved the function to an external file its stopped.
It could probably do with a clean up but this first problem is beyond me.
Form:
Javascript function:
Thanks in advance
James
I do not typically program using javascript however I have built a form that requires your date of birth being entered where I have used select boxes. When the user selects a month the script will work out how many days in that month and then populate the days selectbox and then on to the year.
It was working fine when I had it inside the same page as the form but know I have moved the function to an external file its stopped.
It could probably do with a clean up but this first problem is beyond me.
Form:
Code:
<select class="select" name="month" onBlur="changeDate(this.options[selectedIndex].value);">
<option value="na">Month</option>
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select class="select" name="day" id="day">
<option value="na">Day</option>
</select>
<select class="select" name="year" id="year">
<option value="na">Year</option>
</select>
Javascript function:
Code:
function changeDate(i){
var e = document.getElementById('day');
while(e.length>0){
e.remove(e.length-1);
var j=-1;
if(i=="na")
day_count=0;
else if(i==2)
day_count=29;
else if(i==4||i==6||i==9||i==11)
day_count=30;
else
day_count=31;
while(j++<day_count){
var s=document.createElement('option');
var e=document.getElementById('day');
if(j==0){
s.text="Day";
s.value="na";
try{
e.add(s,null);}
catch(ex){
e.add(s);}}
else{
if(j<10){
j="0" + j;}
s.text=j;
s.value=j;
try{
e.add(s,null);}
catch(ex){
e.add(s);}}}}
var y = 2010;
while (y-->1909){
var s = document.createElement('option');
var e = document.getElementById('year');
s.text=y;
s.value=y;
try{
e.add(s,null);}
catch(ex){
e.add(s);}}
Thanks in advance
James