Commits

Luke Plant  committed d85c28a

Added fallback method for showing placeholder text

  • Participants
  • Parent commits 2aebcac
  • Branches bookings

Comments (0)

Files changed (2)

File cciw/cciwmain/static/css/style.css

     font-weight: bold;
 }
 
+input.placeholder {
+    background: #f0f0f0;
+    color: #808080;
+}
+
 .successMessage
 {
     border: 1px solid #007633;

File cciw/cciwmain/static/js/cciwutils.js

 
     pub.standardformClearError = standardformClearError;
 
-    $(document).ready(function() {
-        $('form.ajaxify').each(function(i, elem) {
-            pub.standardformAddOnchangeHandlers($(this));
-        });
+    return pub;
+})(cciw || {}, jQuery);
+
+
+$(document).ready(function() {
+    // Ajax callbacks for labelled forms
+    $('form.ajaxify').each(function(i, elem) {
+        cciw.standardformAddOnchangeHandlers($(this));
     });
 
-    return pub;
-})(cciw || {}, jQuery);
+    // placeholder fallback for older browsers:
+    var i = document.createElement('input');
+    if (!('placeholder' in i)) {
+        $('[placeholder]').focus(function() {
+            var input = $(this);
+            if (input.val() == input.attr('placeholder')) {
+                input.val('');
+                input.removeClass('placeholder');
+            }
+        }).blur(function() {
+            var input = $(this);
+            if (input.val() == '' || input.val() == input.attr('placeholder')) {
+                input.addClass('placeholder');
+                input.val(input.attr('placeholder'));
+            }
+        }).blur();
+        $('[placeholder]').parents('form').submit(function() {
+            $(this).find('[placeholder]').each(function() {
+                var input = $(this);
+                if (input.val() == input.attr('placeholder')) {
+                    input.val('');
+                }
+            });
+        });
+
+    }
+});
+