0

I want to change the form elements a bit in the login block for D7 to add the following to the input elements:

onblur="if(this.value=='') this.value='Username'" onfocus="if(this.value =='Username' ) this.value=''"

I would prefer not to create a new module just for this via hook form alter, and I did not see a user block to override in the User module.

Is there a template.php function that could be used?

1 Answer 1

0

You dont need to do access the form elements directly like that. You can use some unobtrusive JavaScript with jQuery to do the same thing.

;(function ($){
    Drupal.behaviors.YOUR_FUNCTION = {
        attach: function (context, settings) {
                    // your script goes here...
               };   
    };
})(jQuery);

Create a scripts file and add the above. Add a reference to that file in your .info file.

Then add your script.

Some references if your not familiar with jQuery.

2
  • ah, great approach. I thought about that, but then thought what if they have javascript turned off? I soon realized the error of my logic. thanks!
    – blue928
    Commented Jul 16, 2012 at 0:24
  • Glad I could help ;-)
    – Alex Gill
    Commented Jul 16, 2012 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.