Search code examples
javascriptjqueryhtmlvariablesuser-input

How do you make a header on an HTML page based on user input from a previous page?


I am very new to HTML, css, jQuery, javascript, etc. and on a website I am making, I want to take the user's input and make that the header of another page of my website. I don't understand how to transfer that information from one HTML page to another.


Solution

  • Use local storage .

    To set:

    var UserInput=$('#txtBoxID').val();
    localStorage.setItem(yourkey,UserInput);
    

    To get the value on other page:

     var header = localStorage.getItem(yourkey);
     $('#YourHeaderHtmlID').val(header );
    

    Note that you all do this inside document ready.

    $(function() {
    
    });