the_groover
10-20-2003, 01:30 PM
Hi folks,
I am a newbie to JavaScirpt and I want to do some simple validation. The key is that I want to validate that a month and a year field aren't less than the current month and year. I know that this is blatently incorrect, but I wanted to get an idea from some experts that will point me in the right direction.
Thanks in advanced for your help.
-Tim
function checkccdate() {
var month = new Date.getMonth()
var year = new Date.getYear()
var yesdate = month && year
var formmonth = document.validator.cc_month.value
var formyear = document.validator.cc_year.value
var formdate = formmonth && formyear
if (yesdate < formdate){
alert ("I am sorry your Credit Card Expiration Date is invalid");
}
else (
alert("Everything looks great!...your application has been submitted")
)
}
By the way, here are the two fields from the form. (I numbered month 0 - 11 because of the getMonth thingy.
<select name="cc_month">
<option value="0" selected>Jan</option>
<option value="1">Feb</option>
<option value="2">Mar</option>
<option value="3">Apr</option>
<option value="4">May</option>
<option value="5">Jun</option>
<option value="6">Jul</option>
<option value="7">Aug</option>
<option value="8">Sep</option>
<option value="9">Oct</option>
<option value="10">Nov</option>
<option value="11">Dec</option>
</select>
<select name="cc_year">
<option value="2003" selected>2003</option>
<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
</select>
I am a newbie to JavaScirpt and I want to do some simple validation. The key is that I want to validate that a month and a year field aren't less than the current month and year. I know that this is blatently incorrect, but I wanted to get an idea from some experts that will point me in the right direction.
Thanks in advanced for your help.
-Tim
function checkccdate() {
var month = new Date.getMonth()
var year = new Date.getYear()
var yesdate = month && year
var formmonth = document.validator.cc_month.value
var formyear = document.validator.cc_year.value
var formdate = formmonth && formyear
if (yesdate < formdate){
alert ("I am sorry your Credit Card Expiration Date is invalid");
}
else (
alert("Everything looks great!...your application has been submitted")
)
}
By the way, here are the two fields from the form. (I numbered month 0 - 11 because of the getMonth thingy.
<select name="cc_month">
<option value="0" selected>Jan</option>
<option value="1">Feb</option>
<option value="2">Mar</option>
<option value="3">Apr</option>
<option value="4">May</option>
<option value="5">Jun</option>
<option value="6">Jul</option>
<option value="7">Aug</option>
<option value="8">Sep</option>
<option value="9">Oct</option>
<option value="10">Nov</option>
<option value="11">Dec</option>
</select>
<select name="cc_year">
<option value="2003" selected>2003</option>
<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
</select>