473,394 Members | 1,645 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,394 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 8889
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.