4
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by jsdev
0

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.

1

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>

Edited by @developer: n/a

Votes + Comments
Just Awesome no need to say anymore.
0

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.

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"><br />
	<input type="text" id="myTextBox2" value="Enter text"><br />
	<input type="text" id="myTextBox3" value="Enter text">
</body>

Edited by @developer: n/a

0

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!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.