Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function activatePlaceholders() {
- var detect = navigator.userAgent.toLowerCase();
- if (detect.indexOf('safari') > 0) {
- return false;
- }
- var inputs = document.getElementsByTagName('input');
- for (var i=0;i<inputs.length;i++) {
- if (inputs[i].getAttribute('type') == 'text') {
- if (inputs[i].getAttribute('placeholder') && inputs[i].getAttribute('placeholder').length > 0) {
- var className = inputs[i].getAttribute('class');
- if(inputs[i].value.length < 1){
- inputs[i].setAttribute('class', className + " placeholders");
- }
- inputs[i].onclick = function() {
- if (this.value == this.getAttribute('placeholder')) {
- var className = inputs[i].getAttribute('class');
- className.replace('placeholders', '');
- this.setAttribute('class', className);
- this.value = '';
- }
- return false;
- }
- inputs[i].onblur = function() {
- if (this.value.length < 1) {
- this.value = this.getAttribute('placeholder');
- var className = inputs[i].getAttribute('class');
- this.setAttribute('class', className + " placeholders");
- }
- }
- inputs[i].value = inputs[i].getAttribute('placeholder');
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment