Solved

Compare two form fields containing begin time and end time in AM PM format in a form

Posted on 2014-12-05
2
172 Views
Last Modified: 2014-12-05
I have a simple question. I have a form called form2 that contains two fields. the Begin Time with id "s1Time1" and an End Time with id of "s1Time2". The two fields hold the formats of HH:MM AM or PM. All I need is to be able to tell in a javascript function that the Begin Time can not be greater than the End Time. I am not using any dates or seconds in my time fields.


This is what my form looks like:

<form id="form1" name="form1" method="post" action="">
  <div id="sample1" class="ui-widget-content" style="padding: .5em;">
    <p>
      <label>Start</label>
      <br/>
      <input name="s1Time1" id="s1Time1" value=""/>
      <br/>
      <label>End</label>
      <br/>
      <input name="s1Time2" id="s1Time2" value="" />
    </p>
    <p>
      <label></label>
     
    </p>
  </div>
  <input name="submitbtn" type="submit" id="submitbtn"  value="Submit" />
  </form>
0
Comment
Question by:kbsad1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40483097
var stime = document.getElementById("s1Time1").value;
var etime = document.getElementById("s1Time2").value;

var stime = new Date("January 01, 2000 " + stime);
stime = stime.getTime();

var etime = new Date("January 01, 2000 " + etime);
etime = etime.getTime();

if (stime > etime) {
    alert("earlier")
} else {
    alert("valid time")
}

Open in new window


Didn't do too much testing but it should be fine.

You can test here
http://jsfiddle.net/qxqfj6of/1/
0
 

Author Closing Comment

by:kbsad1
ID: 40483112
Worked great . Thanks
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question