473,804 Members | 3,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

place HTML code with inline javascript into a div

1 New Member
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 "fillsectio n()" 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 3042
acoder
16,027 Recognized Expert Moderator MVP
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
3892
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 data strucure like this: structList =
8
7723
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
4400
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 solution where and which part of the code should be placed/inserted in the main HTML code? Sometimes a Javascript functionality is split up to several parts and/or it makes a big difference where the Javascript code should run/be called (e.g. -...
13
1897
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 tags are hanging in ie when generating a html page in a new window. Works fine in netscape/moz. I know ie does some weird things with scripts but...
1
3372
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 information in other table columns. To make the collapse / expand functionality I want to use JavaScript to display / hide table rows using row.style.display = "inline" / "none". To get references to the table rows they all need unique id's. I want
9
2904
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 no luck though), and searched through the IRT.ORG Faqs (www.irt.org/script/script.htm). The Javascript is designed to open an popup window and then inside that window call another script which will resize that window. There may be another...
4
7819
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 pretty sure I know what the problem is already. I just don't know how to fix it. I'd be very grateful of any help. I'll post what I'm trying to do, what keeps happening, what I believe the problem is, the link to my page and the css, and things...
2
3325
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? I thought the class file had to be compiled and placed in the bin directory or added to the App_Code(as a class file) folder. I don't have it in either it's simply in the root. Now When I compile it and place the dll in the bin and remove the...
10
7439
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 extender to TextBox. Inside a Update panel i have Lable.. and the update panel refreshes each 3 seconds and it fetches data and displays it. But my problem is whenever the data is fetched from Server the textbox watermark flickers. i dont know why it...
0
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10588
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10324
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.