PDA

View Full Version : How to Save Dynamically Created Elements


u jayakodi
10-04-2010, 11:36 AM
u jayakodi
jayakodiu@yahoo.com

Elements created and added to a web page by scripts are not 'saved' when the page is saved. Two simple js functions presented here can save the dynamically created elements; the script and other details of the page creating them are avoided, as may be needed in a graph plottng routine.

Pl. see the enclosed zip file.

tfburges
10-04-2010, 02:53 PM
Your best bet would be to use AJAX to query a server-side script (connected to a database or some kind of file storage) that saves the DOM structure as it is created; and of course when the page is loaded, read from the repository to regenerate the created elements.

If you can't use a server-side script, you may be able to do the same using cookies but... cookies... how do they work?

P.S.
1.5) No homework assignments - Do not post your entire homework assignment and request that other members do it for you. This is considered cheating, and your thread may even be used by your school to prove your guilt. Now, you may ask for advice or help on a specific aspect of your assignment that you're having trouble with. Use common sense as far as what's acceptable in terms of soliciting help with homework assignments.

hotwheelharry
04-26-2011, 01:51 PM
hmm, server side scripts for that... is that really the best bet?

I think you could use localStorage. Much faster/easier to make work.

Cookies... lol.

Kor
04-27-2011, 12:36 PM
u jayakodi
jayakodiu@yahoo.com

Elements created and added to a web page by scripts are not 'saved' when the page is saved. Two simple js functions presented here can save the dynamically created elements; the script and other details of the page creating them are avoided, as may be needed in a graph plottng routine.

Pl. see the enclosed zip file.
That is an IE only solution, as it is based on ActiveX, which is a specific IE language. Don't mention that it will work only under Windows OS. So that, in fact, that is not a JavaScript solution, it is a limited ActiveX / Windows one.

For a modern crossbrowser solution there are two possibilities: either a server-side code (with or without AJAX) or the HTML5 features, like local Storage or even dataBase Storage.

Cookies, are, indeed, improper, as they can store limited content of data.

yogesh249
10-13-2011, 04:40 PM
NO, that is not true....
dynamically added elements are sent to the server side....

I have tested it using a HELLOWORLD type program.

I wrote a html form, a javascript method that adds dynamic fields to the html form. and on submission I can see the values of dynamic fields that were generated via javascript method.

rnd me
10-13-2011, 06:19 PM
for smaller pages:

window.open('data:text/html,'+ escape( "<html>"+
document.documentElement.innerHTML+
"</html>"));

for bigger pages, it can take a LONG time for this to run. i've never seen it actually crash, but it will freeze firefox for a while on big pages (>20kb of html)...