0

I am making a table in HTML which takes user input and saves it to an Ajax server. When the page is refreshed, the newly-inputed text is still there. When someone on a different computer / phone, etc. views the table on my website, however, the changes that someone else had made on their device are not viewable. In other words, is there a way to allow users to dynamically edit content in a table on a website, and then make that information viewable by every person that visits the website after?

I have minimal experience in JS, so more detailed explanations would be helpful! Thanks so much! The code in HTML and CSS is attached below:

td, table tr, th {
 border: 1px solid Black;
 border-collapse: collapse;
}
<!DOCTYPE html>
<html>
<head>
 <link rel="stylesheet" type="text/css" href="WorkLog.css">
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<meta charset="UTF-8">
<title>Work Log</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
<h1>Work Log Template</h1>
 <table id=WorkLog contenteditable=true>
 <tr>
 <th>Item</th>
 <th>Estimated Length</th>
 <th>Comments / Brief Summary (optional)</th>
 <th>Actions</th>
 </tr>
 <tr>
 <td></td>
 <td></td>
 <td></td>
 <td><input type="button" class="BtnPlus" value="+" /><input type="button" class="BtnMinus" value="-" /></td>
 </tr>
 
 </table>
<script type="text/javascript">
 
 $(document).ready(function () {
 
 function addRow() {
 var html = '<tr>' +
 '<td>new item</td>' +
 '<td></td>' +
 '<td></td>' +
 '<td><input type="button" class="BtnPlus" value="+" /><input type="button" class="BtnMinus" value="-" /></td>' +
 '</tr>'
 $(html).appendTo($("#WorkLog"))
 };
$("#WorkLog").on("click", ".BtnPlus", addRow);
});
</script>
<script>
 function deleteRow() {
 var par = $(this).closest('TR');
 par.remove();
};
$("#WorkLog").on("click", ".BtnMinus", deleteRow);
</script>
<script>
$(document).ready(function(){
 $("#WorkLog").blur(function() {
 localStorage.setItem('WorkLogsData', this.innerHTML);
 });
 if ( localStorage.getItem('WorkLogsData') ) {
 $("#WorkLog").html(localStorage.getItem('WorkLogsData'));
 }
});
</script>
</body>
</html>

asked Jul 19, 2016 at 23:23
1
  • localStorage belongs to a browser. If you want other users to see data then you have to save that data on a server side (in a DB or text file) and serve to over people. Commented Jul 19, 2016 at 23:53

1 Answer 1

1

this not AJAX

you are saving the data in the client's browser via localstorage which all it does is save the data entered by the user on your local machine

to make it globally accessible you need to save the data on a DB on your server via AJAX

I would suggest you read these first:

answered Jul 20, 2016 at 1:09
Sign up to request clarification or add additional context in comments.

2 Comments

Oh, that makes sense! I completed the tutorial in the second link, yet I still am confused about how to implement the code their into my specific case. Any tips?
ok you need to save the data entered by the user on your server how [for saving] onclick event fires a js function > that function will send an AJAX request to a specific URL on your server with the data entered by the user > on the server side you accept the data and save it into a mysql table [for displaying] get all the data from your mysql table and display it on the page

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.