knadh / localStorageDB

A simple database layer for localStorage and sessionStorage for creating structured data in the form of databases and tables
http://nadh.in/code/localstoragedb
814 stars 128 forks source link

How do I retrieve a value from local storage and set it in an HTML input field? #94

Closed Sakibthenoobcoder closed 3 years ago

Sakibthenoobcoder commented 3 years ago

I am building a prescription maker. But I am facing a problem. I want to show to localstorage data in the select box. But I can't. So I need help. Actually i just need a function that detects my row index of table and print the data according to the index in the input field. Thanks in advance

function editpres(){   
        var aha = JSON.parse(localStorage.getItem('books'));

        document.getElementById('name').value = aha[0].name;
        document.getElementById('age').value =aha[0].age;
        document.getElementById('sex').value = aha[0].sex;
        document.getElementById('date').value = aha[0].date;
        document.getElementById('disease').value = aha[0].disease;
        document.getElementById('dignosis').value = aha[0].dignosis;

        }

        <html>
        <div>      
            <table class="table table-success table-striped ">
            <thead>
              <tr>
                <th>Patient Name</th>
                <th>Age</th>
                <th>Sex</th>
                <th>Date</th>
                <th>Disease</th>
                <th>Dignosis</th>
                <th>Medicine</th>
                <th>Test</th>
                <th></th>
              </tr>
            </thead>
            <tbody id="book-list"></tbody>
          </table>
        </div>
        </html>
knadh commented 3 years ago

hm, you seem to be just using localStorage to store serialized JSON and not localStorageDB (this library). Please refer to the README on this repository on how to use this library.