473,226 Members | 1,545 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,226 software developers and data experts.

Start Time and End Time Validation

10
I have select boxes for starttime and endtime in hours, minutes and AM/PM.
I need to validate the time so that end time should be greater than start time.
The AM and PM should also be validated.

Any help appreciated !

below is my code
Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2.  <HEAD>
  3.  <script>
  4. function checkTime(){
  5.             var startTimeValue = document.getElementById("startTime");
  6.             var endTimeValue = document.getElementById("endTime");
  7.  
  8.             if( startTimeValue.options[startTimeValue.selectedIndex].value > endTimeValue.options[endTimeValue.selectedIndex].value) {
  9.                 alert("End Time should be greater than Start Time");
  10.                 return false;
  11.             }
  12.  
  13.             return true;
  14.  
  15.         }
  16.  
  17. </script>
  18.  <BODY>
  19.   <table cellpadding="0" cellspacing="0" border="0" >
  20.                                 <tr>
  21.                                 <td> Start Time:</td>
  22.                                     <td>
  23.                                         <select style="font-size: 9pt;" id="startTime" onchange="checkTime()">
  24.                                             <option value="1">1</option>
  25.                                             <option value="2">2</option>
  26.                                             <option value="3">3</option>
  27.                                             <option value="4">4</option>
  28.                                             <option value="5">5</option>
  29.                                             <option value="6">6</option>
  30.                                             <option value="7">7</option>
  31.                                             <option value="8">8</option>
  32.                                             <option value="9">9</option>
  33.                                             <option value="10">10</option>
  34.                                             <option value="11">11</option> 
  35.                                             <option value="12">12</option>                                                                                                                                                                                 
  36.                                         </select></td>
  37.                                         <td>
  38.                                             <select dataSource="actionForm.fromMinutes" style="font-size: 9pt;">
  39.                                                 <option value="0">00</option>
  40.                                                 <option value="1">01</option>
  41.                                                 <option value="2">02</option>
  42.                                                 <option value="3">03</option>
  43.                                                 <option value="4">04</option>
  44.                                                 <option value="5">05</option>
  45.                                                 <option value="6">06</option>
  46.                                                 <option value="7">07</option>
  47.                                                 <option value="8">08</option>
  48.                                                 <option value="9">09</option>
  49.                                                 <option value="9">10</option>
  50.                                                 <option value="9">11</option>
  51.                                                 <option value="9">12</option>
  52.                                                 <option value="9">13</option>
  53.                                                 <option value="9">14</option>
  54.                                                 <option value="9">15</option>
  55.                                                 <option value="9">16</option>
  56.                                                 <option value="9">17</option>
  57.                                                 <option value="9">18</option>
  58.                                                 <option value="9">19</option>
  59.                                                 <option value="9">20</option>
  60.                                                 <option value="9">21</option>
  61.                                                 <option value="9">22</option>
  62.                                                 <option value="9">23</option>
  63.                                                 <option value="9">24</option>
  64.                                                 <option value="9">25</option>
  65.                                                 <option value="9">26</option>
  66.                                                 <option value="9">27</option>
  67.                                                 <option value="9">28</option>
  68.                                                 <option value="9">29</option>
  69.                                                 <option value="9">30</option>
  70.                                                 <option value="9">31</option>
  71.                                                 <option value="9">32</option>
  72.                                                 <option value="9">33</option>
  73.                                                 <option value="9">34</option>
  74.                                                 <option value="9">35</option>
  75.                                                 <option value="9">36</option>
  76.                                                 <option value="9">37</option>
  77.                                                 <option value="9">38</option>
  78.                                                 <option value="9">39</option>
  79.                                                 <option value="9">40</option>
  80.                                                 <option value="9">41</option>
  81.                                                 <option value="9">42</option>
  82.                                                 <option value="9">43</option>
  83.                                                 <option value="9">44</option>
  84.                                                 <option value="9">45</option>
  85.                                                 <option value="9">46</option>
  86.                                                 <option value="9">47</option>
  87.                                                 <option value="9">48</option>
  88.                                                 <option value="9">49</option>
  89.                                                 <option value="9">50</option>
  90.                                                 <option value="9">51</option>
  91.                                                 <option value="9">52</option>
  92.                                                 <option value="9">53</option>
  93.                                                 <option value="9">54</option>
  94.                                                 <option value="9">55</option>
  95.                                                 <option value="9">56</option>
  96.                                                 <option value="9">57</option>
  97.                                                 <option value="9">58</option>
  98.                                                 <option value="9">59</option>
  99.                                                 <option value="9">60</option>
  100.  
  101.                         </select>
  102.                                         </td>
  103.                                         <td>
  104.                                             <select dataSource="actionForm.startampm" style="font-size: 9pt;">
  105.                                                    <option value="0">AM</option>
  106.                                                  <option value="1">PM</option>                                          
  107.                                             </select>
  108.                                         </td>
  109.  
  110.                                     <td>&nbsp; End Time:</td>
  111.                                       <td style="padding-left: 10px;">
  112.                                             <select style="font-size: 9pt;" id="endTime" onchange="checkTime()">
  113.                                                 <option value="1">1</option>
  114.                                                 <option value="2">2</option>
  115.                                                 <option value="3">3</option>
  116.                                                 <option value="4">4</option>
  117.                                                 <option value="5">5</option>
  118.                                                 <option value="6">6</option>
  119.                                                 <option value="7">7</option>
  120.                                                 <option value="8">8</option>
  121.                                                 <option value="9">9</option>
  122.                                                 <option value="10">10</option>
  123.                                                 <option value="11">11</option>
  124.                                                 <option value="12">12</option>                                                                                                                                                                                 
  125.                                             </select>
  126.                                         </td>
  127.                                           <td>
  128.                                             <select dataSource="actionForm.toMinutes" style="font-size: 9pt;">
  129.                                                 <option value="0">00</option>
  130.                                                 <option value="1">01</option>
  131.                                                 <option value="2">02</option>
  132.                                                 <option value="3">03</option>
  133.                                                 <option value="4">04</option>
  134.                                                 <option value="5">05</option>
  135.                                                 <option value="6">06</option>
  136.                                                 <option value="7">07</option>
  137.                                                 <option value="8">08</option>
  138.                                                 <option value="9">09</option>
  139.                                                 <option value="9">10</option>
  140.                                                 <option value="9">11</option>
  141.                                                 <option value="9">12</option>
  142.                                                 <option value="9">13</option>
  143.                                                 <option value="9">14</option>
  144.                                                 <option value="9">15</option>
  145.                                                 <option value="9">16</option>
  146.                                                 <option value="9">17</option>
  147.                                                 <option value="9">18</option>
  148.                                                 <option value="9">19</option>
  149.                                                 <option value="9">20</option>
  150.                                                 <option value="9">21</option>
  151.                                                 <option value="9">22</option>
  152.                                                 <option value="9">23</option>
  153.                                                 <option value="9">24</option>
  154.                                                 <option value="9">25</option>
  155.                                                 <option value="9">26</option>
  156.                                                 <option value="9">27</option>
  157.                                                 <option value="9">28</option>
  158.                                                 <option value="9">29</option>
  159.                                                 <option value="9">30</option>
  160.                                                 <option value="9">31</option>
  161.                                                 <option value="9">32</option>
  162.                                                 <option value="9">33</option>
  163.                                                 <option value="9">34</option>
  164.                                                 <option value="9">35</option>
  165.                                                 <option value="9">36</option>
  166.                                                 <option value="9">37</option>
  167.                                                 <option value="9">38</option>
  168.                                                 <option value="9">39</option>
  169.                                                 <option value="9">40</option>
  170.                                                 <option value="9">41</option>
  171.                                                 <option value="9">42</option>
  172.                                                 <option value="9">43</option>
  173.                                                 <option value="9">44</option>
  174.                                                 <option value="9">45</option>
  175.                                                 <option value="9">46</option>
  176.                                                 <option value="9">47</option>
  177.                                                 <option value="9">48</option>
  178.                                                 <option value="9">49</option>
  179.                                                 <option value="9">50</option>
  180.                                                 <option value="9">51</option>
  181.                                                 <option value="9">52</option>
  182.                                                 <option value="9">53</option>
  183.                                                 <option value="9">54</option>
  184.                                                 <option value="9">55</option>
  185.                                                 <option value="9">56</option>
  186.                                                 <option value="9">57</option>
  187.                                                 <option value="9">58</option>
  188.                                                 <option value="9">59</option>
  189.                                                 <option value="9">60</option>
  190.  
  191.  
  192.                                                  </select>
  193.                                             </td>
  194.                                     <td>
  195.                                         <select dataSource="actionForm.endampm" style="font-size: 9pt;">
  196.                                               <option value="0">AM</option>
  197.                                              <option value="1">PM</option>
  198.                                         </select>                                       
  199.                                     </td>
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.                                         </tr>
  207.                             </table>
  208.  </BODY>
  209. </HTML>
  210.  
  211.  
Oct 24 '08 #1
1 8800
the value of the select boxes is a string right now, try this:


Expand|Select|Wrap|Line Numbers
  1. var start=startTimeValue.options[startTimeValue.selectedIndex].value*1
  2. var end=endTimeValue.options[endTimeValue.selectedIndex].value*1
  3. if( start > end) 
javascript will try to preform the math (*1), and will change the "string" to actual numbers if there aren't any letters in it:) There is a little more logic involved for you to make this work right, but that should get you started:)
Oct 24 '08 #2

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

Similar topics

6
by: Kenneth | last post by:
Hello, I'm having some serious problems debugging a script that I'm trying to make work. I'm working on a form where a user can type in a time (in the format of HH:MM), and another script...
383
by: John Bailo | last post by:
The war of the OSes was won a long time ago. Unix has always been, and will continue to be, the Server OS in the form of Linux. Microsoft struggled mightily to win that battle -- creating a...
3
by: LDD | last post by:
Are there any built in time and/or date validation methods that one can make use of in .NET? thanks folks LDD
2
by: Tim Frawley | last post by:
Source code attached indicates my problem with validation and a button bar save button. Fill the Textbox with some text then tab off the control. The message box will display the text in the...
0
by: Rich | last post by:
I have an ASP.NET application "Modeler" that I adapted from ibuyspy. I worked fine under ASP.NET 1.1 & Visual Studio 2003. I recently installed ASP.NET 2.0 & Visual Studio 2005 Pro. After...
9
by: ThunderMusic | last post by:
Hi, I'd like to create a compile time error in my class... maybe there's a way already built in in the framework so I can achieve what I want... I have 2 constructors in my class. One of them...
6
by: Steve Ryan | last post by:
can anyone send me to some good examples of edit in place for data frid columns i see dot net let me assign a control in the IDE any good sources of reading on editing columns with controls...
6
by: tatata9999 | last post by:
Hi all, I have this simple time management tool designed and developed. And based on a very thoughtful and kind Frenchman's input I've extended its support to international (support all time...
0
by: Arun21084 | last post by:
Hi, Recently I installed an application HP SIP(Service Information Portal) on a Windows 2000 server.The application comes along with an installation of Tomcat 5.0.19. Already there was an Apache...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.