views:

53

answers:

3

Now, this requirement may seem weird. But i would like to know how to achieve this?
I am having an HTML file, which is having few input box, check box, radio button etc. I would like to retain the changes a user [ actually i ] performs on this page. Like if the user has ticked a checkbox then next time anybody open that file should see that checkbox as ticked.

This thing can be done easily using HTTP cookies. But i don't want to use cookies.
The answer can be as simple as "No you can not do that" :)

Edit
That's the problem with not phrasing the question correctly.

I guess i can't use DB as if i will send my HTML page to someone then he/she will not be able to see my changes. I want my changes to be reflected on other systems also. [ thats the reason i was not going for cookies ]. Other solution what i was thinking was, using FileSystemObject. Any other solution ? again the answer can be "No you can not do that" :D

+2  A: 

You could bind the change events of your form elements to an AJAX submit, log the submits to the db and then on any page load grab the latest states from the db for rendering.

Edit

If you want these changes to appear "simultaneously" for other users then you could use jQuery polling to update the page - have the page periodically poll the server for the latest state.

Having said that, if you give them a server link and not the actual file they will see your db changes.

However, it sounds like you want to actually send the file (not send someone to a web server) in which case you could do something like one of these approaches:

  • Your PHP/whatever file (can possibly even do this with javascript) outputs a HTML file with appropriate checked="checked", selected="selected", value="blah" etc. You send this file.

  • Your PHP/whatever file outputs a static reference file. Your HTML file has javascript referencing and using the values stored in this file. You send both of these files around (although value updates only require a changed static reference file).

Graphain
i like your answer, but i would like to re frame my question :)
Rakesh Juyal
+1 anyways.....
Rakesh Juyal
Added an update, let me know if it's on track
Graphain
A: 

You need some method to identify the user when he or she visits again. A browser cookie is useful, because it is stored on the user's computer, which serves as identification. The other serious option is to store the user's preferences in a database. This would, at least, require a server-side language. In addition, you need some way to identify the user, such as username, or, less reliably, IP address.

I hear other options may exist in HTML5, but I don't think those can be used seriously at this time. You can read about it here in Offline Web Applications. It seems to me like something very similar in spirit, although much more powerful, than cookies.

TNi
A: 

I sounds like you want to change the actual file using Javascript - this should be rather difficult. Javascript was designed from scratch as a web scripting language and as such it doesn't have any built in file/IO functionality.

What you can do in Javascript is load ActiveX objects and plug ins. How this works depends a lot on which browser you're using. For instance in IE you could load an ActiveX object (written in VB or whatever) that could edit your file:

var fileWriter = new ActiveXObject("My.FileWriter");
fileWriter.Update("myFile.htm", "inputName", "newValue");

You'd have to write your FileWriter utility though.

Alternatively you could use HTML5's new data storage stuff - but then you're still limited on browser.

Keith
`-1` for ActiveX, sorry.
Delan Azabani
@Delan Azabani - That's a little unfair! I'd never recommend ActiveX in a normal web application, but given what he's trying to do (i.e. have Javascript in an HTML file on disk that changes that file) he doesn't have many options.
Keith
Fair enough, I see what you mean. :)
Delan Azabani
Small problem: I can't undo my vote unless you edit.
Delan Azabani