Storing data on a server for safekeeping and retrieving it when needed

I have a website where users can input text in a form, which is then displayed using a query plugin. However, I noticed that whenever the page is refreshed, all the user input is lost. How can I ensure that the data stays on the screen even after a refresh? Can you help me modify my code to achieve this?

<html>
 <head>

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="textualizer.min.js"></script>
</head>

<style type="text/css">

#txtlzr{color:#585856; font-size:50px; width:1200px; height:100px;
margin-left:10%;
margin-top:80px;
font-family:"futura";
position: fixed;
}
 </style>

<body>

   <div id="txtlzr"></div>
    <form action="#" method="post"/>
      <fieldset>
       <label for="kwote">Comment:</label>
       <input class="kwote" type="text" maxlength="40" id="kwote"
         placeholder="Enter something here."/>
       <lable for="name">Name:</label>
       <input class="name" type="text" maxlength="17" id="name"
         placeholder="Enter your name."/>
       <input class="post" type="button" value="Add comment"
         onclick="add_comment();" />
     </fieldset>
   </form>


 <script language="javascript">
    var COMMENTS_FOR_DISPLAY = new Array('Thanks for the help: nick');

    // Adds a new comment, name pair to the Array feeding textualizer.
    function add_comment() {
      // Retrieve values and add them to Array.
      var new_comment = $('#kwote').val();
      COMMENTS_FOR_DISPLAY.push(new_comment + ': ' + new_name);

      // Reset <input> fields.
      $('#kwote').val('');
      $('#name').val('');
    }

    $(document).ready(function() {
      var txt = $('#txtlzr');  // The container in which to render the list

       var options = {
        rearrangeDuration: 5, // Time a character takes to reach its position
        effect: 'random',     // Animation effect the characters use to appear
        centered: true        // Centers the text relative to its container
  }

  txt.textualizer(COMMENTS_FOR_DISPLAY); // textualize it!
  txt.textualizer('start'); // start
});
</script>
  </body>
</html>
 </html>

Special thanks to Chris for assisting with the input.

Answer №1

There is more to building a website than just the visible code. It also involves incorporating a server-side language and having access to a database server in order to make any significant progress.

If you're unsure about which language or platform to choose, consider checking out the Flask tutorial or the Django tutorial. Both tutorials will guide you through setting up a server, but they use SQLite, a file-based database system, so you won't have to worry about dealing with complex database servers just yet.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When completing a form submission, make sure to eliminate the %5B%5D from the

Whenever I submit a form with multiple checkboxes that share the same name, the resulting URL format is as follows: www.example.com/search.php?myvalue%5B%5D=value1&myvalue%5B%5D=value2 Is there a method to eliminate the %5B%5D in the URL and make it m ...

Utilize JavaScript declarations on dynamically added strings during Ajax loading

Is there a way to append HTML strings to the page while ensuring that JavaScript functions and definitions are applied correctly? I have encountered a confusing issue where I have multiple HTML elements that need to be interpreted by JavaScript. Take, for ...

Putting the database on ice to experiment with new functionalities in Django

I am looking to incorporate a few additional fields into the existing models of my Django app and potentially create a new class. My goal is to test this new feature and ensure that it functions properly. While I can easily revert the code changes using g ...

What is the best way to incorporate polling into the code provided below? I specifically need to retrieve data from the given URL every 60 seconds. How should I go about achieving this

Can you assist me in integrating polling into the code below? <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <script src="https://code.highcharts.com/highcharts.js"> ...

AJAX form in a partial view displaying a summary of validations

I am facing an issue with my application that utilizes an AJAX form. Whenever the form is submitted and fails validation, I return the partial view in which the form resides. In this scenario, I would expect the Validation Summary to be displayed. However, ...

Turning off the button in CakePHP

Is there a way to create a function that, when a disable button is clicked for a record, it changes the value in the 'active' column to 0 within the ['Album'] array? The default value of this column should be set to 1. I have tried: if ...

Problem encountered when transferring JSON data to PHP for file writing

After spending numerous hours researching potential solutions, I still can't seem to fix the issue at hand. Admittedly, I am fairly new to PHP, so it's possible that I am overlooking a small detail. The problem lies in the fact that I have a form ...

Querying with Laravel 5.2 using the WhereNotIn method

I'm dealing with a complex search query where I need to exclude users who have blocked the searching user. I'm feeling confused and stuck, so I could really use some help. In my database, the `blocked_users` table looks like this: id user_id b ...

How can objects be securely shared in PHP?

To securely share an instance of a config object in PHP that contains sensitive information such as database usernames and passwords, the approach must be carefully considered. The dynamic nature of the database user adds complexity to the sharing process. ...

Control the HTML button's state according to the information received from the server

I am currently working with datatable Jquery and using an ajax call to retrieve data from the server. Let's assume that the database consists of three attributes: "Attribute1, Attribute2, Status". Depending on the Status attribute, I need to enable or ...

The offspring of php5-fpm and their tasks

Curious about something. I currently have a 128mb vps hosting a blog that only receives around one hundred visitors daily. My setup includes nginx and php5-fpm. Due to the low traffic and RAM, I opted to configure fpm with just one server in static mode. D ...

User access is managed through websockets

Currently, I am integrating Websockets into my php project using Ratchet and Symfony. Upon user login, they are automatically connected to a specific channel within the websocket connection. Messages can be pushed to the channel and displayed on the client ...

What is the standard size for PHP files, or the suggested maximum limit?

I created a tool at where users can upload a .php file with comments and spaces, and it will compress it for a smaller file size. It functions similar to but is web-based and provides instant results. Once you click upload, you receive a prompt to downl ...

ajax request within a function

Could you assist me with this issue? When the success function is triggered, I am able to obtain the necessary result. However, the ajaxFunction ultimately returns an empty value. ajaxFunction = function(lastNum){ var json_res = ''; ...

How can one display blog data (stored as a PDF) from a database alongside other different results (stored as

I have successfully displayed a PDF file from my database as a blob using the header("Content-type:application/pdf") method. Now, I am looking to also display some additional string results along with this PDF file. Is it feasible to achieve this while d ...

Creating a dynamic number of datasets in Chart JSWith Chart JS

After extensive searching, I thought I was on the verge of finding a solution several times, but unfortunately, no luck! I am aware that a similar question was posted yesterday: React Chartjs, how to handle a dynamic number of datasets, but it remains una ...

The JQuery JavaScript function fails to complete its execution

Question: How can I resolve the issue where my PHP file returns a large JSON string with approximately 2000 elements, each having 14 child elements? When using jQuery AJAX to fetch the JSON and populate an ID-identified table, the filling process stops mid ...

What techniques can be used to streamline this regex and eliminate the need for recursion?

Regex: (?|`(?>[^`\\]|\\.|``)*`|'(?>[^'\\]|\\.|'')*'|"(?>[^"\\]|\\.|"")*"|(\?{1,2})|(:{1,2})([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)) ...

Can a PHP script be run and its result included in another script before being displayed?

I have a PHP script located at http://example.com/myapp/myscript.php that is currently running on an Apache server. When this URL is accessed from a mobile app, the script performs its logic and sets HTTP headers and body with data in JSON format, which th ...

Transmit JSON information from one webpage and dynamically retrieve it from another page via AJAX while both pages are active

I am attempting to transfer JSON data from page1 when the submit button is clicked and then retrieve this data dynamically from page2 using AJAX in order to display it in the console. I am unsure of the correct syntax to accomplish this task. There was a s ...