473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Date object, expiration.....

hi, i've a basic credit card info form, checks name, card type and if number is valid...... i got these working ok

here's the code i have so far. i'm trying to make a function, getdate(), but am a little stumped with the date object.

how does it read the values from the month select list and the year select list in the html?


Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="JavaScript">
  2.  
  3.  
  4.  
  5.     function validateForm()
  6.     {
  7.             formObj = document.formCard;
  8.  
  9.             if(formObj.name.value == "")
  10.             {
  11.                 document.getElementById("noName").style.visibility = "visible";    
  12.                 return false;    
  13.             }
  14.  
  15.             if(formObj.card.value == "")
  16.             {
  17.                 document.getElementById("noCard").style.visibility = "visible";    
  18.                 return false;    
  19.             }
  20.  
  21.             if(document.getElementById("number").value.length != 16)
  22.             {
  23.                 document.getElementById("numberLength").style.visibility = "visible";    
  24.                     return false;
  25.             }    
  26.  
  27. /*            var date = new date();
  28.             alert(date.getMonth());
  29.  
  30.             getdate();    */    
  31.  
  32.  
  33.     }
  34. /*    function getdate()
  35.  
  36.     var d = new Date()
  37.  
  38.     {
  39.  
  40.  
  41.     }*/
  42.  
  43. </SCRIPT>
html

Expand|Select|Wrap|Line Numbers
  1.       <table width="100%" border="0" cellspacing="0" cellpadding="0">
  2.         <tr>
  3.           <td align="left">
  4.            <form id="formCard" name="formCard" method="post" action="" onSubmit="return validateForm()"> 
  5.  
  6.             Name:<div id="noName">Please fill out your name</div>
  7.             <br />
  8.             <input name="name" type="text" id="name" size="30" />
  9.       <br />
  10. <br />
  11.             Card Type:<div id="noCard">Please select a card type</div>
  12.             <br />
  13.   <select name="card" id="card">
  14.     <option value=""> </option>
  15.     <option value="Mastercard">Mastercard</option>
  16.     <option value="Visa">Visa</option>
  17.   </select>
  18.   <br />
  19.   <br />
  20.             Card Number:<span style="color:red;" id="numberLength">Card number length incorrect</span>
  21.             <br />
  22.   <input name="number" type="text" id="number" size="35" />
  23.   <br />
  24.   <br />
  25.             Expiry Date:<span style="color:red;" id="date"></span>
  26.             <br />
  27.   <select name="month">
  28.     <option>Month</option>
  29.     <option value="01">01</option>
  30.     <option value="02">02</option>
  31.     <option value="03">03</option>
  32.     <option value="04">04</option>
  33.     <option value="05">05</option>
  34.     <option value="06">06</option>
  35.     <option value="07">07</option>
  36.     <option value="08">08</option>
  37.     <option value="09">09</option>
  38.     <option value="10">10</option>
  39.     <option value="11">11</option>
  40.     <option value="12">12</option>
  41.   </select>
  42.   <select name="year">
  43.     <option>Year</option>
  44.     <option value="2007">2007</option>
  45.     <option value="2008">2008</option>
  46.     <option value="2009">2009</option>
  47.     <option value="2010">2010</option>
  48.   </select>
  49.           <br />
  50.           <br />
  51.           <input type="submit" name="Submit" value="Submit"/>
  52.           </form></td>
  53.         </tr>
  54.       </table>
Nov 8 '07 #1
3 1702
acoder
16,027 Expert Mod 8TB
You should be giving your month and year select objects IDs, then access them using document.getElementById().

You can still access them using e.g. document.getElementById("formCard").month.value.
Nov 8 '07 #2
ok, i've id's on all the month and year values, i'm still unsure how to code my if statement.

i know i need to get the date object involved, as the date will keep changing.....

any ideas?


Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="JavaScript">
  2.  
  3.  
  4.  
  5.     function validateForm()
  6.     {
  7.             formObj = document.formCard;
  8.  
  9.             if(formObj.name.value == "")
  10.             {
  11.                 document.getElementById("noName").style.visibility = "visible";    
  12.                 return false;    
  13.             }
  14.  
  15.             if(formObj.card.value == "")
  16.             {
  17.                 document.getElementById("noCard").style.visibility = "visible";    
  18.                 return false;    
  19.             }
  20.  
  21.             if(document.getElementById("number").value.length != 16 && isNaN) 
  22.             {
  23.                 document.getElementById("numberLength").style.visibility = "visible";    
  24.                     return false;
  25.             }    
  26.  
  27.  
  28.  
  29.             dateCheck();    
  30.  
  31.  
  32.     }
  33.  
  34.     function dateCheck()
  35.     {
  36.             if (document.getElementById("month").value < [09])
  37.                 document.getElementById("date").style.visibility = "visible";    
  38.                     return false;    
  39.     }
  40.  
  41.  
  42.  
  43. </SCRIPT>
Nov 8 '07 #3
acoder
16,027 Expert Mod 8TB
Use parseInt on the value: parseInt(document.getElementById("month").value)
Nov 8 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Christophe Lance | last post by:
Hello, I use PHP session cookie to store an id number. I know how to set a cookie expiration date using the setcookie function, but how to set an expiration date when the cookie is created by...
30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
0
by: Rock | last post by:
Hi,all: I have find a example to set expiration date of word permission object, but it was using VBA code. Dim objUserPerm As Office.UserPermission Set objUserPerm =...
3
by: hasanainf | last post by:
Hi all, What will be the best database design for an inventory control that uses expiry date for its products. Over a period of time, a particular product will have many expiry date and that...
2
by: Frederic Gignac | last post by:
Hiya all, My buddy and I got a bug with the expiration date of a cookie. When we want to look out the expiration date, the only thing we've got, it's 01/01/0001. As we know, when we want to...
2
by: Naga Kiran | last post by:
Hi I want to set expiration date for my web based application. for eg it has to be worked for 15 days from the date when it was installed. More over i dont want to use system date to check the...
0
by: Diffident | last post by:
Hello All, I cached a string object into Cache and set absolute expiration date. Now, I would like to retrieve the absolute expiration date of that object. Any API's available? Any pointers?...
10
by: Mike9900 | last post by:
Hello, I would like to store application expiration date in a file and store that file in a secure place, so the application can access the file for all the users on that computer. ...
3
by: dave | last post by:
I need to compute an expiration date based on the number of hours, days, or months purchased. The expiration date needs to be expressed in minutes something like '1260481600'. How can I get the...
2
by: Steve Covert | last post by:
Does anybody have any clever technique to implement an expiration date in a WinForms app, such that it could outsmart any user who tries to change the system clock to avoid expiration?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.