Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Thursday 9 April 2015

Introduction
In this article I will explain how to clear textbox value on focus using jquery. Using jQuery event focus(), it’s simple to clear textbox on focus. This method will be applied to all textbox on the webpage.


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

To clear Particular textbox onfocus using jQuery:

$(function () {
$('#txtuser').focus(function () {
$(this).val('');
})
})
Full Source Code for Sample Application:

<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>
 <fieldset style="width:300px">
    <legend><strong>Listbox Example</strong></legend>
<div>
<b>Enter Text:<br />
    </b><br />
Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" id="txtuser" value="Enter Your text" /><br /><br />
Company: <input type="text" id="txtName" value="Maziksolutions" />
</div></fieldset>
</body>

</html>
Categories: , , ,

0 comments:

Post a Comment