show-notice
hide-notice

Tuesday 2 July 2013

jQuery Clear Textbox Value on focus




Introduction

Here I will explain How to use jQuery to clear textbox value on focus or simple jQuery code snippet to clear textbox value onfocus using jQuery.



Bind focus event for all textboxs to clear values onfocus using jQuery


$(function () {
$('input[type=text]').focus(function () {
$(this).val('');
})
})

To clear Particular textbox onfocus using jQuery

$(function () {
$('#txtuser').focus(function () {
$(this).val('');
})
})

For complete example check below code


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Clear Textbox onfocus using jQuery</title>
<script src="http://code.jquery.com/jquery-1.8.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('input[type=text]').focus(function () {
$(this).val('');
})
})
</script>
</head>
<body>
<div>
<b>Enter Text:</b>
<input type="text" id="txtuser" value="Welcome to GohilInfotech.in" />
<input type="text" id="txtName" value="GohilInfotech.in" />
</div>
</body>
</html>

SHARE THIS POST   

0 comments :

Post a Comment

Design by Gohilinfotech | www.gohilinfotech.blogspot.com