954,566 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Javascript to jquery ghost text disappearing text help

http://www.web-source.net/javascript_disappearing_form_text.htm

This shows exactly what I want to do but it does not work in chrome localhost the text just stays there. I don't understand why everything is always screwed up in local host :@ . I want to make this with Jquery to make it more accessible for my users. Thanks for your all of your help in advance.

minimogul
Light Poster
31 posts since Oct 2010
Reputation Points: 11
Solved Threads: 0
 

Did you link to the jQuery library?

ichigo_cool
Junior Poster
101 posts since Jul 2010
Reputation Points: 6
Solved Threads: 4
 

Yes I did but it doesn't work. I don't know im going to keep trying. Im a noob in Jquery so it might take a while for an update until I'm done.

minimogul
Light Poster
31 posts since Oct 2010
Reputation Points: 11
Solved Threads: 0
 

Hi try this...

<head>
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>

	<script type="text/javascript">

	$(document).ready(function(){
		$('#myTextBox').click(function(){
			$('#myTextBox').val("");
		});
		
		$('#myTextBox').blur(function(){
			var currentText = $('#myTextBox').val();
			if(currentText == "")
			{
				$('#myTextBox').val("Enter text");
			}
		});
	});		
	</script>
</head>

<body>
	<input type="text" id="myTextBox" value="Enter text">
</body>
@developer
Junior Poster in Training
70 posts since Nov 2010
Reputation Points: 13
Solved Threads: 10
 

Thanks a million works like a charm. All I can say is wow. Sorry to bother you but can you recommend some place I can read up on this stuff because I would just like to know how this works and get into jquery. Another thing is can I do this for two inputs. Like copy the code and change it to the other inputs name and it would do both? Thanks again help me out so much.

minimogul
Light Poster
31 posts since Oct 2010
Reputation Points: 11
Solved Threads: 0
 

Hi minimogul,

There are lots of jQuery tutorials available, me also a beginner in this. You can start learning from the official jQuery site http://docs.jquery.com/Tutorials . Also checkout the API reference given.

This can be used for multiple text boxes.

<head>
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>

<script type="text/javascript">
	
	$(document).ready(function(){
		$('input:text').click(function(event){
			$(event.target).val("");
		});
		
		$('input:text').blur(function(event){
			if($(event.target).val() == "")
			{
				$(event.target).val("Enter text");
			}
		});
	});
	
</script>
</head>

<body>
	<input type="text" id="myTextBox" value="Enter text">
	<input type="text" id="myTextBox2" value="Enter text">
	<input type="text" id="myTextBox3" value="Enter text">
</body>
@developer
Junior Poster in Training
70 posts since Nov 2010
Reputation Points: 13
Solved Threads: 10
 

Just a word to the wise, not everyone uses a mouse or a touch screen, so instead of ONCLICK event use ONFOCUS, it will handle on click and when users tab to it as well.

Cheers!

jsdev
Newbie Poster
1 post since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: