Drupal jQuery input value function
Hi, I can't seem to get his code to work which I took from:
http://webdevmania.com/archive/top_10_jquery_snippets_including_jquery_1.4/I want it so that when a user click on a textfield (classname "form-text") the value should disappear and reappear when clicking outside of it. Just a user-friendly function to put it simple.
- <?php
- drupal_add_js(
- 'swap_val = [];
- $(".form-text").each(function(i){
- swap_val[i] = $(this).val();
- $(this).focusin(function(){
- if ($(this).val() == swap_val[i]) {
- $(this).val("");
- }
- }).focusout(function(){
- if ($.trim($(this).val()) == "") {
- jQuery(this).val(swap_val[i]);
- }
- });
- });',
- 'inline'
- );
- ?>
If you are familiar with Drupal you probably know that you have to add <?php tags and the drupal_add_js-function stated here:
http://api.drupal.org/api/function/drupal_add_js/7But I can't get it to work!? In Drupal I have activated php-code in my textareas, so I am allowed to use that. I'm not getting any errors so I guess I'm doing something right. However, I do get errors if I really want to, just to try if things are really working.
Any guesses what could be wrong, or missing in my code? And yes I am certain that the class-name for the input fields are "form-text".
Edit: Just wanted to say that I got it to work with puting document ready-function :P