Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CHECKBOX checked, then validate, NOT Checked, DO NOT VALIDATE

Status
Not open for further replies.

gu102

Technical User
May 5, 2002
7
US
All,
I am in need of HELP! If CHECKBOX is checked, then validate MM/DD/YYYY where all must be a number, if not checked, do not validate. I already incorporated a "Click to enable drop list of days" to the right of it.

------------------START VIEW CODE------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<script language=&quot;javascript&quot;>
function enableDisable()
{
document.AddContact.NotifyDay.disabled = !(document.AddContact.NotifyDay.disabled);
}
</script>
</head>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<form method=&quot;post&quot; action=&quot;&quot; name=&quot;AddContact&quot;>
<table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;2&quot; cellpadding=&quot;2&quot;>
<tr>
<td width=&quot;90%&quot; class=&quot;inputtxt&quot;>
<select name=&quot;BirthMonth&quot;>
<option value=&quot;00&quot; Selected>Month
<option value=&quot;01&quot;>January
<option value=&quot;02&quot;>February
<option value=&quot;03&quot;>March
<option value=&quot;04&quot;>April
<option value=&quot;05&quot;>May
<option value=&quot;06&quot;>June
<option value=&quot;07&quot;>July
<option value=&quot;08&quot;>August
<option value=&quot;09&quot;>September
<option value=&quot;10&quot;>October
<option value=&quot;11&quot;>November
<option value=&quot;12&quot;>December
</select>
/
<select name=&quot;BirthDay&quot;>
<option value=&quot;00&quot; Selected>Day</option>
<option value=&quot;01&quot;>01</option>
<option value=&quot;02&quot;>02</option>
<option value=&quot;03&quot;>03</option>
<option value=&quot;04&quot;>04</option>
<option value=&quot;05&quot;>05</option>
<option value=&quot;06&quot;>06</option>
<option value=&quot;07&quot;>07</option>
<option value=&quot;08&quot;>08</option>
<option value=&quot;09&quot;>09</option>
<option value=&quot;10&quot;>10</option>
<option value=&quot;11&quot;>11</option>
<option value=&quot;12&quot;>12</option>
<option value=&quot;13&quot;>13</option>
<option value=&quot;14&quot;>14</option>
<option value=&quot;15&quot;>15</option>
<option value=&quot;16&quot;>16</option>
<option value=&quot;17&quot;>17</option>
<option value=&quot;18&quot;>18</option>
<option value=&quot;19&quot;>19</option>
<option value=&quot;20&quot;>20</option>
<option value=&quot;21&quot;>21</option>
<option value=&quot;22&quot;>22</option>
<option value=&quot;23&quot;>23</option>
<option value=&quot;24&quot;>24</option>
<option value=&quot;25&quot;>25</option>
<option value=&quot;26&quot;>26</option>
<option value=&quot;27&quot;>27</option>
<option value=&quot;28&quot;>28</option>
<option value=&quot;29&quot;>29</option>
<option value=&quot;30&quot;>30</option>
<option value=&quot;31&quot;>31</option>
</select>
/
<input type=&quot;text&quot; name=&quot;BirthYear&quot; size=&quot;4&quot; maxlength=&quot;4&quot; value=&quot;&quot;>
<span class=&quot;smallText&quot;>(mm/dd/yyyy)</span></td>
</tr>
<tr valign=&quot;top&quot;>
<td width=&quot;90%&quot; class=&quot;smallText&quot; bgcolor=&quot;#F1F1F1&quot;>
<input type=&quot;checkbox&quot; name=&quot;Notify&quot; value=&quot;1&quot; onClick=&quot;enableDisable();&quot;>
Notify me via email,
<select name=&quot;NotifyDay&quot; Disabled>
<!--<option value=&quot;&quot;>Select</option>-->
<option value=&quot;0&quot; selected>the day of</option>
<option value=&quot;1&quot;>1 day before</option>
<option value=&quot;2&quot;>2 days before</option>
<option value=&quot;5&quot;>5 days before</option>
<option value=&quot;7&quot;>7 days before</option>
<option value=&quot;10&quot;>10 days before</option>
</select>
this contact's birthday.</td>
</tr>
</table>
<input type=&quot;Submit&quot; name=&quot;Save&quot; value=&quot;Save&quot; onClick=&quot;return validate(this.form)&quot;>
</form>
</body>
</html>
---------------------END SAMPLE CODE---------------------

ANY HELP would be greatly appreciated
 
Code:
function validate(f){
   var goodData = true;

   if(f.Notify.checked){
      //Code for validating date.
      // Set goodData = false for bad date.
   }

   //Code for validating other form info.
   // Set goodData = false for other bad data.
   
   return goodData;
}
Put the call to validate() in the <form> tag instead of in the <input type=&quot;submit&quot;> tag.

Code:
<form . . . onsubmit=&quot;return validate(this)&quot;>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top