View Full Version : Resolved Remove form input defaults on click
nicksalad
02-21-2009, 11:13 AM
Hello, the script is placed here: http://blake-walters.com/2008/07/remove-form-input-defaults-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.
$('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.
Snookerman
02-21-2009, 12:28 PM
Put this in the head section of your page:
<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!
nicksalad
02-21-2009, 12:42 PM
Put this in the head section of your page:
<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.
Snookerman
02-21-2009, 12:57 PM
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.
nicksalad
02-21-2009, 12:58 PM
Im having problems with the submit button, i don't know why, but when i pressed it, it shrink to half size o.o
Snookerman
02-21-2009, 01:05 PM
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 (http://www.dynamicdrive.com/forums/showthread.php?t=42040)
Good luck!
nicksalad
02-21-2009, 01:22 PM
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 (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/clearingdefaulttext.html
Check it out, and tell me which one u think is better.
Thanks again!
Snookerman
02-21-2009, 02:00 PM
It works fine for me, could you please post a link to your site where you are testing this?
nicksalad
02-21-2009, 04:00 PM
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...
Snookerman
02-21-2009, 04:06 PM
Try adding this:
$('input[type="text"], textarea').each(function() {
Good luck!
nicksalad
02-21-2009, 05:10 PM
Try adding this:
$('input[type="text"], textarea').each(function() {
Good luck!
Awesome! TY bro ;)
you gotta love jQuery... :)
Snookerman
02-21-2009, 05:41 PM
Your welcome, glad to help!
you gotta love jQuery... :)
Amen!
You can go to your first post in this thread, click http://www.dynamicdrive.com/forums/images/buttons/edit.gif then click Go Advanced and add the Resolved prefix to the thread title.
This will let other users know the problem has been solved.
Good luck with your site!
nicksalad
02-21-2009, 05:49 PM
Your welcome, glad to help!
Amen!
You can go to your first post in this thread, click http://www.dynamicdrive.com/forums/images/buttons/edit.gif then click Go Advanced and add the Resolved prefix to the thread title.
This will let other users know the problem has been solved.
Good luck with your site!
Done, thanks!
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.