Forum Moderators: open
I know javascript reads from 0 to 11 for months but I need to make it user friendly please can someone help I have tried everything i know.
Sorry if this is the wrong place to post I couldn't find any Javascript catergory.
---------
<html>
<head>
var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var begin_year = 2000
var year_count = 100
var begin_today = true // true = the start day must be bigger than the day of today
var min_days = 0 // the mimum days between the start day and enddate
var max_days = false // the maximum days between the start day and enddate
//Set this value on (max_days = false) for unlimited days
var set_on_today = true // set the startday on today
var end_start = 8 // only importent when you set the set_on_day on true, the value of the end date is the date of today + end_start
var bday,bmon,byear,eday,emon,eyear
var todayd = new Date()
function init(form)
{
bday = form.bday;
bmon = form.bmon;
byear = form.byear;
eday = form.eday;
emon = form.emon;
eyear = form.eyear;
if(set_on_today == true)
{
bday.options[(todayd.getDate()-1)].selected = true;
bmon.options[todayd.getMonth()].selected = true;
byear.options[(todayd.getFullYear() - begin_year)].selected = true;
milli = -(0 - todayd) + (1000*60*60*24*end_start)
var todayde = new Date(milli)
eday.options[(todayde.getDate()-1)].selected = true;
emon.options[todayde.getMonth()].selected = true;
eyear.options[(todayde.getFullYear() - begin_year)].selected = true;
}
}
function value_date(cday,cmon,cyear)
{
tempdate = new Date(cyear.value,cmon.value,cday.value)
if((cday.value == tempdate.getDate()) && (cmon.value == tempdate.getMonth()) && (cyear.value == tempdate.getFullYear())) return true
return false
}
function check()
{
if(!value_date(bday,bmon,byear))
{
alert("The start date is an invalid date!\nPlease reselect.");
return false
}
if(!value_date(eday,emon,eyear))
{
alert("The end date is an invalid date!\nPlease reselect.");
return false
}
if(begin_today == true)
{
var tempdate = new Date(byear.value,bmon.value,bday.value);
var tempdatet = new Date(todayd.getFullYear(),todayd.getMonth(),todayd.getDate());
if(tempdatet > tempdate)
{
alert("The start date must bigger than the date of today!");
return false
}
}
var tempdatee = new Date(eyear.value,emon.value,eday.value);
if(tempdate > tempdatee)
{
alert("The end date must be bigger than the start date!");
return false
}
one_day = 1000*24*60*60
days_between = (tempdatee - tempdate)/one_day
if(days_between < min_days)
{
alert("The minimum days between is "+ min_days + " days!");
return false
}
if(max_days!= false)
{
if(days_between > max_days)
{
alert("The maximum days between is "+ max_days + " days!");
return false
}}
}
</script>
</head>
<body>
<FORM action="" method = "post" name = "form" onsubmit = "return check(this)" >
<!-- Below are the date boxes and script to be placed anywhere in form -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Start </td>
<td colspan="2"><select name=bday size=1 class=selecter>
<script language="JavaScript">
for(i=1;i<=31;i++) document.write("<option value="+ i + ">"+ i);
</script>
</select> <select name=bmon size=1 class=selecter>
<script language="JavaScript">
for(i=0;i<12;i++) document.write("<option value="+ i + ">"+ months[i]);
</script>
</select> <select name=byear size=1 class=selecter>
<script language="JavaScript">
for(i=0;i<year_count;i++) document.write("<option value="+ (i+begin_year) + ">"+ (i+begin_year));
</script>
</select></td>
</tr>
<tr>
<td>End
</td>
<td><select name=eday size=1 class=selecter>
<script language="JavaScript">
for(i=1;i<=31;i++) document.write("<option value="+ i + ">"+ i);
</script>
</select> <select name=emon size=1 class=selecter>
<script language="JavaScript">
for(i=0;i<12;i++) document.write("<option value="+ i + ">"+ months[i]);
</script>
</select> <select name=eyear size=1 class=selecter>
<script language="JavaScript">
for(i=0;i<year_count;i++) document.write("<option value="+ (i+begin_year) + ">"+ (i+begin_year));
init(document.form)
</script>
</select></td>
</tr>
</table>
<td> <br>
<input name="" type="submit">
</form></body></html>
For example
if I submit 20th June 2003 it sends perfectly
However
if I submit 20th May 2003 its warns me the start date should be more then today.
Now how can I get that to work for June and not May.
Javascript reads it that May is the current month being the value of 5.
Any thoughts
The results end up being 0 instead of 1 for january etc. which is very confusing, specially when it will be received by people who have only just discovered the power of email.
I am not really a programmer but I have been able to manipulate one or two php scripts and javascripts just to personalise it.
I have searched the internet and asked around for another version of this form but with no success, all their is to offer are pop up calander pickers and date checkers that check manually inputed dates which is again not very user friendly.
Their must be a solution some how, I have tried moving the months down one for instance putting ("","january","february",".....) but again the javascript will still only recognise 5 as being May.
Its so annoying and I have been very close to cracking it
but theirs always something not right.
I am very gratefull for your help and advice thanks.
function value_date(cday,cmon,cyear)
{
tempdate = new Date(cyear.value,cmon.value-1,cday.value)
if((cday.value == tempdate.getDate()) && (cmon.value-1 == tempdate.getMonth()) && (cyear.value == tempdate.getFullYear())) return true
return false
}
2) some changes in the function check():
var tempdate = new Date(byear.value,bmon.value-1,bday.value);
and
var tempdatee = new Date(eyear.value,emon.value-1,eday.value);
3) the script in the select boxes for the months:
for(i=0;i<12;i++) document.write("<option value="+ (i+1) + ">"+ months[i]);
This should pass the validation and post human readable month numbers.