473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

place HTML code with inline javascript into a div

Placing HTML code with inline javascript into a div both as rendered HTML(the intended final purpose) and shown as RAW text HTML (for the user to copy and paste into their own webpage.)

Here is the setup. Yes, this is a heavily dynamic and AJAX driven page.
one section shows both a display of raw HTML code for the purpose of a user being able to copy paste this code (which contains inline javascript) into their own webpage.

a sample being here:
Expand|Select|Wrap|Line Numbers
  1. <table width="150" border="0" bordercolor="#000000" ><tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="8" bgcolor="#808080"> </td> <td width="*" bgcolor="#808080"> <font face=Helvetica color=#000000 size=2 > honda is a long name</font> </td> <td width="90" bgcolor="#808080" align="right"><font face=Helvetica color=#000000 size=2 ><script language="JavaScript" type="text/javascript" > var m = new Array( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ); var d = new Date(); document.writeln( m[d.getMonth()] + ". " + d.getUTCDate() + ", " + d.getFullYear() ) </script></font> </td> </tr> <tr> <td width="8" bgcolor="#696969"> </td> <td bgcolor="#696969" colspan="2"> data </td> </tr> </table></table>
  2.  
Note the inline Javascript to generate the date.
this is generated on the fly by a user of the site as they select desired colors and fonts etc... for the output code.


THE ISSUE:
when the user wants to see not the raw code but the sample output, they select so on a dropdown and the target div is replaced with the above code BUT the "<" are not converted to "&lt;" as they where for the RAW display.
OK, i noticed i had issues when the filler text had "<script" or "</script" so in the (to-be-placed) text i had "<script" as "Lscript" and "L/script" which are converted back in the "fillsection()" code.

================================================
target code section:
-------------------------------
Expand|Select|Wrap|Line Numbers
  1. <div name="codesection">
  2. <div>
  3.  
  4. replace code
  5. -------------------------------
  6. function fillsection(sectionid, secdata){
  7.     while (secdata.indexOf( "^" ) > -1 )
  8.         secdata = secdata.replace( "^", "\"" );
  9.     while (secdata.indexOf( "Lscript" ) > -1 )
  10.                 secdata = replaceAll(secdata, "Lscript","<script");
  11.     while (secdata.indexOf( "L/script" ) > -1 )
  12.                 secdata = replaceAll(secdata, "L/script","</script");
  13.  
  14.     var replace = document.getElementById(sectionid);
  15.     var wrappingDiv = document.createElement('div');
  16.     wrappingDiv.className="text/html";
  17.     var divdata = ""+ secdata;
  18.     wrappingDiv.innerHTML = ""+divdata;
  19.     replace.innerHTML= '';
  20.     replace.appendChild(wrappingDiv);
  21. }
  22.  
  23.  
  24.  
the doctor:
EMAIL REMOVED
Mar 21 '07 #1
1 3014
acoder
16,027 Expert Mod 8TB
For the raw html, use <pre> tags or put the code into a textarea, and for the sample output, just set the innerHTML. That way, you don't need to replace anything.
Mar 22 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Gregor Horvath | last post by:
Hi, Before I reinvent the wheel I`d like to ask if someone has done this before since I did not find an advice at Google. The goal is to create a dynamic Tree View in HTML. Say I have a...
8
by: Lucy | last post by:
help! javascript inline of an HTML to open an HTML in a target window. Something like... <html> <head> <title>test</title> </head> <body>
18
by: Arthur Connor | last post by:
Is there a way of extracting the Javascript code from the "normal" HTML code (e.g. similar to CSS code which can be put into a separate file) ? If you offer a solution: can I determine in your...
13
by: nobody | last post by:
Hello all, I've searched just about everything and although I can see that other people are having problems, but theirs don't seem to relate, so in a last ditch attempt, my posting! Script...
1
by: OM | last post by:
I am trying to present tree-structure information using a html table and JavaScript. Each tree node is displayed in the first column in a table row. The tree node can also have additional...
9
by: Robby Bankston | last post by:
I'm working on some code and am running into brick walls. I'm trying to write out Javascript with Javascript and I've read the clj Meta FAQ and didn't see the answer, read many similar posts (with...
4
by: TheCeej | last post by:
I'm sorry to post what is ultimately a myspace problem, but I'm sure I'd still be having this problem with any html/css document, so the answer would more than likely be able to help anyone out. I'm...
2
by: Reggie | last post by:
Hi and TIA! I have a class file located in my root directory with all me web pages. I call/use the class and it works fine. I have no imports statements aspx or codebehind. My question is why? ...
10
dj12345
by: dj12345 | last post by:
Hi, (Asp.net + Ajax) I am creating a page which will fetch data from server without postbak of a page.. I have 2 controls on this page TextBox and Lable. I have assigned TextBoxWatermark...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.