|
|
|
|
![]() ![]() |
May 18 2005, 08:01 AM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 372 Joined: 16-August 04 From: Spain Member No.: 824 |
Hi,
I have the next html page CODE <html> <head> <script> <!-- function insertcode() { var code ="<p> blablabal babala babababab</p><h1>here comes header</h1><span>fadfafa<a href=\"fadfaf\">anchor</a>blalbababa</span>" var myText = document.createTextNode(code); document.getElementById("content").appendChild(myText); } --> </script> </head> <body> <div id="content"> </div> <a href="javascript:insertcode()">Insert Code</a> </body> </html> This code insert the data as text. The html tags are not treated like markup. I need to insert the code in a time. I mean i can not go tag per tag. (E.g. document.createElement("p")... ) Is there any method to insert a pice of html code into a div and keep it like code not like text in Javascript? I hope you understand my problem. If not please tell me. Thanks in advanced for your help. |
|
|
|
May 18 2005, 08:30 AM
Post
#2
|
|
|
Desperately seeking "any key" to continue... ![]() Group: Admin Posts: 3,627 Joined: 23-April 05 From: Trap17 storage box Member No.: 6,042 myCENT:33.80 |
I couldn't understand what you were trying to do. I think you are trying to place another HTML/text page in your HTML page.
I saw this code somewhere in this forum but I cannot find who wrote it at this time. A apologize to the author for posting without crediting you. I will come back and correct it once I find it. (or someone PM me if you find it) HTML <object type="text/x-scriptlet" width=100% height="250" data="Your Html File(TextFile )"> </object> This simple liner, I was told, that allows you to place another html/text page into your html page. It's a document within the document. I'm telling ya, we got some brilliant codeboys here! |
|
|
|
May 18 2005, 08:40 AM
Post
#3
|
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 1,161 Joined: 9-May 05 From: Brisbane, QLD Member No.: 6,818 |
QUOTE(mizako @ May 18 2005, 06:01 PM) Is there any method to insert a pice of html code into a div and keep it like code not like text in Javascript? Why is it necessary to insert it as HTML instead of javascript? It should still validate OK. And why are you using javascript to insert the code in the first place? Why not just type it out? |
|
|
|
May 18 2005, 06:32 PM
Post
#4
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 372 Joined: 16-August 04 From: Spain Member No.: 824 |
QUOTE(Tyssen @ May 18 2005, 08:40 AM) Why is it necessary to insert it as HTML instead of javascript? It should still validate OK. And why are you using javascript to insert the code in the first place? Why not just type it out? Ok, i will try to explain myself better. Basically i am working on a Remote Scripting using hidden frames (i will explain what it is this in another topic). project. I have a database in MySQL where in one table i have a biography in XHTML. I access this table with PHP and i retrive this XHTML code. Then the Javascript function obtains the code and has to insert it into a this "div" element. As i explain in my first post. ;-) I know the mechanismus is complicated but i have to do it in this way. I hope you both understand better what i am asking for. I did not understand your solution BuffaloHELP but thanks both of you for your answers. Does anyone knows one can i solve this Javascript Issue? |
|
|
|
May 18 2005, 10:23 PM
Post
#5
|
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 1,161 Joined: 9-May 05 From: Brisbane, QLD Member No.: 6,818 |
QUOTE(mizako @ May 19 2005, 04:32 AM) Ok, i will try to explain myself better. Basically i am working on a Remote Scripting using hidden frames (i will explain what it is this in another topic). project. I have a database in MySQL where in one table i have a biography in XHTML. I access this table with PHP and i retrive this XHTML code. Then the Javascript function obtains the code and has to insert it into a this "div" element. You don't need javascript to write out the code, you can use PHP. You're using just about the same language anyway and you're already using PHP to retrieve the info from the database. It seems logical that you would then use PHP to just print it out using echo or print. You could use PHP code to print your whole page if you wanted to: CODE <?php print "<head>"; print "<title>Your title</title>"; print "<body>"; etc. |
|
|
|
May 19 2005, 12:45 PM
Post
#6
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 372 Joined: 16-August 04 From: Spain Member No.: 824 |
QUOTE(Tyssen @ May 18 2005, 10:23 PM) You don't need javascript to write out the code, you can use PHP. You're using just about the same language anyway and you're already using PHP to retrieve the info from the database. It seems logical that you would then use PHP to just print it out using echo or print. You could use PHP code to print your whole page if you wanted to: As i wrote in my second message i am trying to implement Remote Scripting which aims to reduce the code (avoiding redundant markup) sent by the server to the client. That it is to say that the PHP scripts just send plain text to the client and the client creates the interface by means of Javascript. I know PHP and i know that i can write the whole page with PHP but i need to do it by Javascript. I did not want to begging a topic about Remote Scripting in this thread (maybe in another one), i just wanted to obtain a Javascript solution for the problem i exposed. I appreciate a lot your help but please answer me with a Javascript solution if you know it. Thanks in advanced! |
|
|
|
May 23 2005, 07:22 PM
Post
#7
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 372 Joined: 16-August 04 From: Spain Member No.: 824 |
Hello,
I found the solution :-) . Somebody point me to the "innerHTML" method. The Code with the included solution is the next: HTML <html>
<head> <script> <!-- function insertcode() { var code ="<p> blablabal babala babababab</p>"; code += "<h1>here comes header</h1>"; code += "<span>fadfafa<a href=\"fadfaf\">anchor</a>blalbababa</span>"; document.getElementById("content").innerHTML = code; } --> </script> </head> <body> <div id="content"> </div> <a href="javascript:insertcode()">Insert Code</a> </body> </html> This post has been edited by BuffaloHELP: May 23 2005, 08:20 PM |
|
|
|
May 23 2005, 08:00 PM
Post
#8
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 283 Joined: 10-October 04 Member No.: 1,637 |
oh you got it..
i read ur topic and just floating with javascript site to find about this!! i swear.. anyway, hey u forgot to put code tag on last post as you r hurry right!!! |
|
|
|
![]() ![]() |
![]()