0

So I am making a website (in HTML) where the user can permanently add text to the content of the website. So if someone vists the website after that, he sees the modified content.The modification should be permanent and should not disappear after reload. For this I used the following code :

        <form id="myform" method="POST" action="">
            <input type="text" name="textbox" value="">
            <input type="button" name="button1" value="SUBMIT" onclick="func()">
        </form>
        <br>
        <p id="Test"></p>
        <script>
            function func()
            {
                var x=document.getElementById("myform");
                var text=x.elements[0].value;
                document.getElementById("Test").innerHTML+=text;
            }
        </script>

But the changes are made only on the client side and are not made on the website. So how can I change the source code of the website based on user Input so the changes are made permanently.In this case, how can the change made to <p id="Test"></p> remain permanent as it returns to its default value after page reload. Many Thanks !

2
  • What is your web server? That is where you need to modify the page source.
    – Josh Wulf
    Commented Feb 29, 2020 at 11:07
  • You can't do this using static HTML files alone. You need to use a server-side platform (eg. PHP) with a database to store the persistent data.
    – Jackson
    Commented Feb 29, 2020 at 11:37

1 Answer 1

1

This process containing two steps to perform.

  1. You have performed ,collected user input from client.
  2. You will have to send this data to Your server and server will than saved this data on your database , then your html page get updated data from server and user will see that modified content.

For Sending data to server you have to use ajax post request to send data to server like that

request = $.ajax({
    url: "Your server url",
    type: "post",
    data: data
});

// Callback handler that will be called on success
request.done(function (response, textStatus, jqXHR){
    // Log a message to the console
    console.log("Hooray, it worked!");
});

then server will received it and data saved to database.

5
  • ok the data is saved in the database. Now how will it be updated on the client's browser without reloading the site.
    – JoeBrar
    Commented Feb 29, 2020 at 13:36
  • in browser first it will be updated as you have told above , after page reloading ,it will fetching data from database and that will updated data on page Commented Feb 29, 2020 at 13:57
  • But I want it to dynamically keep updating without reloading the page.If one client adds something then it should be instantly visible to all other clients present on website without having to reload. How can I do this?
    – JoeBrar
    Commented Feb 29, 2020 at 14:11
  • Is there a way that the website keeps checking if the database has been updated, and if it has, then display the updated database.
    – JoeBrar
    Commented Feb 29, 2020 at 14:24
  • you can do this by using real time database (like firebase) , with very ease, other solutions are complex Commented Feb 29, 2020 at 14:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.