Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Remove form input defaults on click

  1. #1
    Join Date
    Jan 2007
    Posts
    58
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Remove form input defaults on click

    Hello, the script is placed here: http://blake-walters.com/2008/07/rem...faults-on.html

    The problem is, i don't know how to include it on my site, to make it work, im really noob at js. Please tell me what i have to add to make it work.

    Code:
    $('input, textarea').each(function() {  
     $(this).focus(function() { 
      if($(this).val() == this.defaultValue) 
        $(this).val(""); 
      }); 
      $(this).blur(function() { 
        if($(this).val() == "")      $(this).val(this.defaultValue); 
      }); 
    });

    Thank you.
    Last edited by nicksalad; 02-21-2009 at 05:49 PM.

  2. #2
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    Put this in the head section of your page:
    HTML Code:
    <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js">
    </script>
    <script type="text/javascript">
    $(function() {
     $('input, textarea').each(function() {  
      $(this).focus(function() { 
       if($(this).val() == this.defaultValue) 
         $(this).val(""); 
       }); 
       $(this).blur(function() { 
         if($(this).val() == "")      $(this).val(this.defaultValue); 
       }); 
     });
    });
    </script>
    Good luck!

  3. #3
    Join Date
    Jan 2007
    Posts
    58
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Snookerman View Post
    Put this in the head section of your page:
    HTML Code:
    <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js">
    </script>
    <script type="text/javascript">
    $(function() {
     $('input, textarea').each(function() {  
      $(this).focus(function() { 
       if($(this).val() == this.defaultValue) 
         $(this).val(""); 
       }); 
       $(this).blur(function() { 
         if($(this).val() == "")      $(this).val(this.defaultValue); 
       }); 
     });
    });
    </script>
    Good luck!
    Thank you for that, but, is it me or it has "extra checks"? i guess it also checks for sql injection and stuff blocking some characters? am i right? if thats correct could you just remove all the unnecessary stuff and just leave the needed to make it work?

    Thank you.

  4. #4
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    I'm not sure I understand what you mean. If you are referring to the code I added, I can explain it for you. The first two lines are to import the jQuery library from Google. The extra function tag means "run this when the document is ready". The script tags are there because it's script code. Other than that, it's just the code you posted.

  5. #5
    Join Date
    Jan 2007
    Posts
    58
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default New one

    Im having problems with the submit button, i don't know why, but when i pressed it, it shrink to half size o.o

  6. #6
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    If you want help with your code, please post a link to your site so we can take a look.

    You could also take a look at this thread that deals with the same issue:
    http://www.dynamicdrive.com/forums/showthread.php?t=42040

    Good luck!

  7. #7
    Join Date
    Jan 2007
    Posts
    58
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Snookerman View Post
    If you want help with your code, please post a link to your site so we can take a look.

    You could also take a look at this thread that deals with the same issue:
    http://www.dynamicdrive.com/forums/showthread.php?t=42040

    Good luck!
    I already found a working one, the problem was, and maybe you can fix it, it was making vanish all the <inputs> including buttons, not only text, etc.

    The link is here: http://www.yourhtmlsource.com/forms/...faulttext.html

    Check it out, and tell me which one u think is better.

    Thanks again!

  8. #8
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    It works fine for me, could you please post a link to your site where you are testing this?

  9. #9
    Join Date
    Jan 2007
    Posts
    58
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Snookerman View Post
    It works fine for me, could you please post a link to your site where you are testing this?
    i'm running it on my local computer, try to download the .js from the link u gave me and place it on your web directory (else ur site will need to connect to a remote site all the time), change the path to your local dir and try. I just did that and started messing around...

  10. #10
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    Try adding this:
    Code:
    $('input[type="text"], textarea').each(function() {
    Good luck!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •