PDA

View Full Version : storing long html code in javascript


mbhramar
04-17-2008, 10:41 AM
Hi,
I need to store a long formatted HTML code in a variable in javascript.
What I am doing right now is the following : (Just a random example)

txt = '<b>hello world</b> \
<h3> Menu 1 </h3>\
<h3> Menu 2 </h3>\
';

However I have fairly long Html code to assign to a js variable.

Can anyone please give me a better solution than one above. What would be great is that if I could simply create HTML on the fly with design tools like dreamweaver & then copy that HTML code & assign it to a variable using any good technique.

Right now I am using dreamweaver to design the HTML code. But I have to sit & manually correct the code appending 'slashes' to it like shown above.

Please help.

mlseim
04-17-2008, 02:49 PM
Is there a reason that you cannot use PHP?

This would not only solve your problem, but you would not
need to use any Javascripting, as it would all be server-side
instead of client-side.

You can also mix PHP along with your HTML.

You can also tell your webhost (or server) to process all .html (or .htm)
as PHP ... so you don't need to change your file extensions to .php

In order to test your web pages, you will need to upload them and view
online (unless you have your own server).

All dynamic web page generation should be done with PHP, Perl, or some
other server-side programming language.

mbhramar
04-17-2008, 03:07 PM
yes. i am using php wth zend framework. but i have to use javascript to store html to dynamically show content using ajax.

i use:
txt = '<b> hello world</b>';

document.write(txt);

i need to know a simpler method to do this

hammer65
04-17-2008, 07:15 PM
Using document.write after a page loads will reload the page. AJAX scripts normally manipulate existing markup wherever possible only changing the contents of a specific tag. You are taking the wrong approach to this.