Jump to content

Letting the user add rows to tables


Intercepted
 Share

Recommended Posts

Is it possible to give the user the ability to add rows to a table through a button or input box and have it save the added rows permanently?Right now I have the ability to add rows working but once I refresh the page the rows are gone.This is how I'm currently doing to add a new row:

$('#myTable > tbody:last').append('<tr><td></td></tr>');
Edited by Intercepted
Link to comment
Share on other sites

Javascript only lives as long as the page lives. In order to preserve state like that, you are most likely going to want to employ a database (or a file could work) to maintain/preserve the content permanently.

Link to comment
Share on other sites

Can I use a file like an XML document without having to run a php server? Is there a way to do this all client side?I just want it to be possible for someone with no knowledge of HTML to be able to add new entries
there's really no way to do it on the client side unless you were able to make use of HTML5's local storage, but as to be expected, its support is limited. You can use any file that you are comfortable using. It could be argued that one can make a basic user/admin interface so that anyone wishing to update the entries can use that to interface with database instead.edit: for clarity though, it would be best if you could supply more details on the data you are trying to store, given it's complexity is what would best determine the path (and file type) to choose.edit edit: localStorage would be user dependent, and not persist for anyone but that one specific user. Edited by thescientist
Link to comment
Share on other sites

What I'm trying to do is have a phone list on a HTML web page to circulate around the building for people. Every week or so it needs to be updated and I'm looking for an easy way to do that. The person updating the phone list won't have a lot of knowledge in HTML so I want to make it as simple as possible. PHP and server side methods are not an option since I'm working in a controlled environment. The data isn't complicated at all, it's just a list of names and numbers.

Link to comment
Share on other sites

You can't do it without a server to process and save the data, end of story. Any other alternative means the changes only appear on a single computer, and would require a specific browser. If you want a centralized server-based application that anyone can update and view, then you obviously need a server that is capable of processing the data. Maybe you should set up a Google Docs spreadsheet and give everyone access to that, which would require Google accounts for each person.

Link to comment
Share on other sites

what do you define as a controlled environment? As in no access to PHP/SQL on the server?

Edited by thescientist
Link to comment
Share on other sites

It just wouldn't work here. I would have to run the PHP server myself and that's a little too much for this small task. By controlled environment I mean a government owned company. Everything on the computers are managed by the government. Google docs won't work because all our information needs to be within our network. Looks like I'll just have to teach the receptionist how to add new entries in HTML. Thanks for the responses

Link to comment
Share on other sites

I think we were missing some of what you were saying. If only one person is in charge of updating this directory file or whatever, then you can use a flat file. As long as all the other people just need to see the output, and not have to make any changes themselves, it will work. I think what was missing here was an accurate description of the problem at hand. User implies any random web user, meaning multiple people from all over the web. It appears to be in fact that the user is really just one static person, and that they will be the only one in charge of making the changes, correct?

Edited by thescientist
Link to comment
Share on other sites

You would need to download the flat file through AJAX. Easily done. AJAX typically communicates with an executable, but it does not have to. Addressing a request object to a .txt file will simply return the text contents.

Link to comment
Share on other sites

That's correct, only one person will be doing the editing. Sorry I'm completely oblivious to anything ajax. How would I use it to read and write information for my table from a flat file?EDIT: I'm playing around with this example right here: http://www.w3schools.com/ajax/ajax_xmlfile.aspbut I can't seem to get it working

Edited by Intercepted
Link to comment
Share on other sites

I'm playing around with this example
That's not the most useful example if you're not going to use XML. When we've referred to a flat file, I think we're assuming a list of tab-delimited values:
Mary Lamb	555-1001Bob Smith	555-1002Tracy Byrd	555-1003

which is very easy to parse and iterate through. (Note: I enter tabs, but the board software converts them to spaces. I mean tabs, though.)

Edited by Deirdre's Dad
Link to comment
Share on other sites

in the case of IE, you would have to manually change everyone's security setting, or just recommend people use a different browser. are people going to have manually open the pages themselves over the network, literally opening directory.html themselves?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...