By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,319 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

Date object, expiration.....

P: 47
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
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
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

P: 47
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
Expert Mod 15k+
P: 16,027
Use parseInt on the value: parseInt(document.getElementById("month").value)
Nov 8 '07 #4

Post your reply

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