Keith Keith - 5 months ago 14
Javascript Question

Restoring placeholder value to a search box after reset has been clicked

I am editing some javascript that has a search box with a variable as follows

var secondSearchTerm = $('#2nd-search').val();


In the HTML code '2nd-search' has a placeholder 'Enter search term'

I also have a reset button that clears the search as follows:

$("#2nd-reset-btn").on("click", function () {
return myNetwork.resetSecondSearch();
})


What I would like to do is to get the search box to re-populate with the placeholder when reset is clicked. Right now the last entered term remains in the search box.

Any ideas on how I can edit the code to do this?

Many thanks!

Answer

hi refer this link https://plnkr.co/edit/EtLmby5BdD5Yn70EIBRD?p=preview

js

// Add your javascript here
$(function(){

$("#reset").on("click", function () {     
   return $('#username').val('');
 });

});

html

<input type="text" name="name"  id = "username" placeholder="uname"/>
<button id="reset">Reset </button>
Comments