Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically generate HTML page from users input 2

Status
Not open for further replies.

msturges

Programmer
Mar 29, 2001
32
ZA
Hi Guys,

Sorry if my subject was not descriptive enough, I really didn't know how to phrase it.

Anyway, here's my problem. I need to create an interface (web page) with a normal form which contains a regular textarea object wherein the user can code raw HTML to make up the contents of another page.

When the user is done they have the opportunity to 'preview' the page before the data gets written to a database.

I know I can reference the value attribute of the textarea in the opener page without submitting the form however I'm having a problem getting it to display the HTML in the called page.

Is there a tag that I can use to assign the value of the textarea parsed to, and, it will be interpreted by the browser as straight forward HTML??

Hope this all makes sense.

Thanks for any help that comes my way.

Regards
Mike
 
Are your users going to enter a full HTML page (including HTML, HEAD, BODY, ... tags) or a just a part of BODY ? Water is not bad as long as it stays out human body ;-)
 
Hi Targol,

The users only have to worry about a part of the body. The purpose is to fill an already created template HTML file with Content HTML supplied by the user.
 
Sooo ....
What you can do is quite simple :
1 ) Give an id attribute to the tag in wich you want the user code to be added within. This tag can be the BODY tag, a DIV, a TD or whatever you want. Let's choose a DIV for example :
Code:
<DIV id=&quot;myContainer&quot;></DIV>
2 ) on page loading event, call a function that'll add the HTML code to this container :
Code:
<BODY onLoad=&quot;addHTMLtoContainer()&quot;>
3 ) Create the function (let's say the HTML code is stored in a global var called &quot;userHTML&quot;) :
Code:
<Script language=&quot;Javascript&quot;>
  function addHTMLtoContainer() {
    var o_Container = document.getElementById(&quot;myContainer&quot;);
    o_Container.innerHTML = userHTML;
  }
</Script>

And ... here we are !!!
Water is not bad as long as it stays out human body ;-)
 
I actually can't believe it's that simple. Thank you very much.
 
Excellent post Targol!

Msturges - don't forget to load the text string into a hidden form field or another textarea so that the user can submit it or edit it - depending on what you're going to do with it... Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048

mikewolf@tst-us.com
 
Thanx for your congratulations Mike, this compliment targets straigth my little worm heart comming from the javascript god you are LOL LOL LOL
Water is not bad as long as it stays out human body ;-)
 
msturges -- is it possible that you could post a url for the page when it is complete?? I'd love to see how you utilized the suggestions offered by Targol and mwolf00....
 
I second the Excellent post Targol!
very descriptive and the work flow was perfect.


_________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
 
That's too much... I'll become shy... LOL
By the way thanx to all. Water is not bad as long as it stays out human body ;-)
 
so if mwolf is the javascript god what's that make me[cry]

j/k _________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
 
I believe in all the gods that are written under the temple front &quot;This forum's top experts!&quot; ... do you prefer Marble or Bronze for your statue ???
LOL Water is not bad as long as it stays out human body ;-)
 
Targol,

Just a quick question, you seem to know your javascript quite well. Will this code work for all browser types and versions or would it be restricted to certain types and versions. If it is restricted, do you know which of the major browsers and versions would support it?

Thanks
 
msturges : this script will need a browser that suports... scripts !!! and the getElementById() method that makes it cross browser for every V4+ browsers I think. Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top