Created
October 14, 2010 14:53
-
-
Save walterdavis/626300 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
| <head> | |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
| <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/prototype/1.6/prototype.js"></script> | |
| <title>Placeholder Text</title> | |
| <script type="text/javascript" charset="utf-8"> | |
| // <![CDATA[ | |
| document.observe('dom:loaded',function(){ | |
| $$('.placeholder').each(function(elm){ | |
| if(elm.getAttribute('alt')){ | |
| var defaultText = elm.getAttribute('alt'); | |
| if(!elm.present()){ | |
| elm.setValue(defaultText); | |
| elm.addClassName('default'); | |
| elm.observe('focus',function(evt){ | |
| if(this.value == defaultText){ | |
| this.clear(); | |
| this.removeClassName('default'); | |
| } | |
| }); | |
| elm.observe('blur',function(evt){ | |
| if(this.value == ''){ | |
| this.setValue(defaultText); | |
| this.addClassName('default'); | |
| } | |
| }); | |
| } | |
| } | |
| }); | |
| }); | |
| // ]]> | |
| </script> | |
| <style type="text/css" media="screen"> | |
| .placeholder.default { | |
| color: #aaa; | |
| } | |
| label { | |
| width:112px; | |
| font-size: 11px; | |
| display: inline-block; | |
| text-align: right; | |
| padding-right: 8px; | |
| } | |
| .indent { | |
| margin-left: 120px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="PageDiv"> | |
| <form action="" method="get" accept-charset="utf-8"> | |
| <p><label for="some_field">Some Field</label><input type="text" name="some_field" class="placeholder" value="" alt="Some Field" id="some_field"/></p> | |
| <p><label for="another_field">Another Field</label><input type="text" name="another_field" class="placeholder" alt="Another Field" value="" id="another_field"/></p> | |
| <p><input type="submit" class="indent" value="Continue"/></p> | |
| </form> | |
| </div> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $$('.placeholder').each(function(elm){ | |
| if(elm.getAttribute('alt')){ | |
| var defaultText = elm.getAttribute('alt'); | |
| if(!elm.present()){ | |
| elm.setValue(defaultText); | |
| elm.addClassName('default'); | |
| elm.observe('focus',function(evt){ | |
| if(this.value == defaultText){ | |
| this.clear(); | |
| this.removeClassName('default'); | |
| } | |
| }); | |
| elm.observe('blur',function(evt){ | |
| if(this.value == ''){ | |
| this.setValue(defaultText); | |
| this.addClassName('default'); | |
| } | |
| }); | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment