skip to Main Content

How to display what i searched in the search box after getting result…eg: if searched for apple in a search box after getting result how to display the apple in the search box

How to display what i searched in the search box after getting result

2

Answers


  1. Get the value of the search box:

    let searchTerm = document.getElementById("search-box").value;
    

    Display the search term in the search box:

    document.getElementById("search-box").value = searchTerm;
    

    You can place this in the func that displays the search results. Then it updates the search box with the search term after displaying the results.

    Login or Signup to reply.
  2. You can use localStorage element in your code to store the current textbox value. It will stay until you remove it. For Example,

    <form id="form1" action="#" method="post" >
        Selected Employee <input type="text"  name="EmployeeName" id="text1">
                         <input type ="submit" value="check">
    </form> 
    

    and js part is,

    $(document).ready(function () {
                $("#form1").submit(function () {
                    window.localStorage['text1_val'] = $("input[id = 'text1']").val();
                });
                $(window).load(function () {
                    $("input[id = 'text1']").val(window.localStorage['text1_val']);
                });
            });
    

    You need jQuery in your code to run this code.
    Hope this will help you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search