Permalink
Browse files

simple form input example

  • Loading branch information...
1 parent 04723f9 commit d0ea668de87922cd7e5eff568d6cde885c3d480e @zackdever committed Sep 10, 2012
Showing with 23 additions and 0 deletions.
  1. +22 −0 example.html
  2. +1 −0 time.js
View
22 example.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+ <head><title>time example</title></head>
+ <body>
+ <p>
+ <input autofocus> = <span id="result"></span>
+ </p>
+ <script src="time.js"></script>
+ <script>
+ window.onload = function() {
+ var result = document.getElementById('result')
+ , text = document.getElementsByTagName('input')[0];
+
+ result.innerText = Time().toString();
+
+ text.onkeyup = function() {
+ result.innerText = Time(text.value);
+ };
+ };
+ </script>
+ </body>
+</html>
View
1 time.js
@@ -47,6 +47,7 @@
}
Time.prototype.toString = function() {
+ if (this.hours == undefined || this.minutes == undefined) return 'invalid';
var minutes = this.minutes < 10 ? '0' + this.minutes : this.minutes;
return this.hours + ':' + minutes;
}

0 comments on commit d0ea668

Please sign in to comment.