I have created a form using HTML, now I won't save the input data into my browser's local storage DB. I want to same multiple inputs, not just one.
how do I do it
I believe I need to use javascript but I'm not strong with it and am still learning it.
I have done the CSS and HTML.

Recommended Answers

All 4 Replies

Let's see the code you're using. We can't provide any suggestions without seeing what you're trying.

it's not posting my code for some reason. this is my first time so can you please help me. there are no curly braces and there's a max of 4 spaces for indentation, but still not posting

You can post your code by clicking the third button from the left and pasting it there.

I would need to see the source code to be able to fully and properly answer the question, however I can provide an example of using the local storage, as well as a useful guide including all the different functions for dealing with it. First off, you will need to use JavaScript to access the local storage pragmatically. The good news is that you don't need to be an expert to do it, accessing the local storage is fairly simple.

You can check out the guide here: Local Storage Guide

Now, in your post you seem to be asking if it's possible to save multiple keys at once. This is possible, however it will take multiple executions. To make this easy, you can use a for loop to go through each text box with a set class.

<html>
    <head>
        <title>Some form</title>
        <script>
            function run() { //This function will run upon pressing the button
            var items = document.getElementsByClassName("ex")
                for (let i = 0; i < items.length; i++) { //In this for loop, each object under the class name "ex" gets its value stored under whatever its name value is
                    localStorage.setItem(items[i].name, items[i].value)
                }
            }
        </script>
    </head>
    <body>
        <form>
            <label for="fname">First name:</label>
            <br>
            <input class="ex" type="text" id="fname" name="first_name">
            <br>
            <label for="lname">Last name:</label>
            <br>
            <input class="ex" type="text" id="lname" name="last_name">
            <br>
            <input type="button" value="Click me" onclick="run()">
        </form>
    </body>
</html>

See it in action here: Redirect
Make sure you open inspect element and go to application so you can see the values get added upon clicking the button.

Anyways, hopefully this helps. If you're still confused, you can ask me about it. Hopefully I'll remember to respond.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.