How To Clear Input Field on Focus using JavaScript?

Today, We want to share with you javascript clear input field.In this post we will show you javascript reset input field, hear for how to clears textbox value after submit in html? we will give you demo and example for implement.In this post, we will learn about onchange jquery with an example.

javascript reset input field Example

When the input field gets focus, replace its current value with an empty string.

Read Also:  how to show an image in php from mysql database example?

<input type="text" onfocus="this.value=''" value="The text">

Example 1: Clears Input Field on Focus

<!DOCTYPE html>
<html>
<body>

<p>javascript clears input field - gets focus:</p>
<input type="text" onfocus="this.value=''" value="Pakainfo">

</body>
</html>

Example 2: Clears Input Field with a Button

<!DOCTYPE html>
<html>
<body>

<p>javascript clear input field on click:</p>
<button onclick="document.getElementById('liveTxt').value = ''">Clears input field</button>

<input type="text" value="Pakainfo" id="liveTxt">

</body>
</html>

I hope you get an idea about jquery reset input value.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.