fahmijaafar
fahmijaafar

Reputation: 185

Permanently save user input data into html

i'm html newbie here so please be lenient with ur answer.

i want to permanently save changes made when i key in different value into the textbox for this html file. for now, everytime i refresh the browser, the data get back to the original value. haha, how do i change it so that the value that i entered will be saved instead, even after i close the tab and reopen it. thanks.

    <table>
<tr>
<td>Current Limit</td>
<td> <div id="newlimit" >100</div> </td>
</tr>
<tr>
<td>Set New Limit</td> 
<td><input type="number" id="updatelimit"></td> 
</tr>
<tr>
<td><button onclick="fupdatelimit()">Save</button><td>
</tr>
<tr>
<td>Limit shown in RM</td>
</tr>
</table>

for javascipt,

function fupdatelimit() {
var y = document.getElementById("updatelimit").value;
newlimit.innerHTML= y;      
    }

thanks for ur help. :D

Upvotes: 2

Views: 10013

Answers (3)

Yerken
Yerken

Reputation: 1942

  1. You want the change to be persistent, when user access the data from the same browser - Store data in localStorage. You can access localStorage using javascript, and the data will be stored only in the current browser that is open.
  2. You want the change to be persistent regardless of where user opens your page from. In this scenario the data needs to be synced with the server. Most common approach is to store the data in your server database. What you do further can be either:
  3. Pass the data along with serving html file, i.e. server reads the data from the database and passes it along with the html file.
  4. OR serve html file from the server. Then request the data from the server using ajax request. Once data is fetched u need to populate the required fields.

EDIT after additional questions

think of it this way. Whenever you open any page on the web, some server sends an html file to your browser to be rendered. HTML itself it just a collection of markup (the table, buttons, textboxes) , everything else (images, content of textboxes etc.) is being loaded from the server (the same guy sending you the html file) , be it database, collection of static images or anything else.

you can certainly store your data in the text file, but it needs to be served from somewhere, most commonly all data pertinent to your website is to be stored in your server (database, images, text files). However the most common approach is to store data in the database. Why not just store in the text file? There are many reasons, but simply speaking same reason why you put your eggs in the egg packet and don't just put it on the floor.

if you want to learn server side scripting and databases, I'd suggest to pick up any for your taste. Most beginners start with PHP(Server side scripting) and MySQL(database), which is arguably the easiest and fastest solution to start with due to large number of tutorials for beginners.

Upvotes: 4

Ece
Ece

Reputation: 148

You need a database for that. Using PHP and MySQL you can do this easily. Enjoy your new adventure.

Upvotes: 0

sunoy14
sunoy14

Reputation: 23

You will need a server side language to save the update. Javascript is client side and runs on the browser only. The changes made with javascript will execute in the browser only, not in the server. When you reload, the server sends back the original file.

Upvotes: 0

Related Questions