javascriptasp.net-corerazorlocal-storagetableheader

How to display localStorage value in a table header?


I have the following js function that is used to get the saved value of an input field:

function getSavedValue(e) {
    if (!localStorage.getItem(e)) {
        return "";
    }
    return localStorage.getItem(e);
}

The following is an example of how I use this js function:

var paymentMonth = document.getElementById("monthHR_PaymentMonth");

paymentMonth.value = getSavedValue("monthHR_PaymentMonth");

How can I use this function to grab the paymentMonth value and display it in a table column header?:

<th>Payment May 2022</th>

Where May 2022 is the value saved.


Solution

  • How can I use this function to grab the paymentMonth value and display it in a table column header?: You can try to add an id to the <th></th>:

    <th id="monthHR_PaymentMonth"></th>
    

    and then use the following code to add text to it:

    $("#monthHR_PaymentMonth").append(getSavedValue("monthHR_PaymentMonth"));