Reply
From text box to HTML preview
Old 05-21-2006, 09:37 PM From text box to HTML preview
Super Talker

Posts: 104
Location: San Diego, Ca
How in the world would i go about making a webpage that has a text box on it. Someone types in their html code into it, and the page will create a preview of the html they have put in the box?

I thought it would be ez, but after a little research.. i have no idea where to get started other than making a simple form with a textbox on it.

__________________
Porch Monkey. And that's the truth.
iqchicken is offline
Reply With Quote
View Public Profile Visit iqchicken's homepage!
 
When You Register, These Ads Go Away!
     
Old 05-21-2006, 09:58 PM Re: From text box to HTML preview
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Wireless Audio
Posts: 2,314
Name: Keith Marshall
Location: West Hartford, CT
Probably be able to define a JS function in the head that when called, it opens a new window with the document.write placing contents from the textarea field
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 05-21-2006, 10:01 PM Re: From text box to HTML preview
Super Talker

Posts: 104
Location: San Diego, Ca
i'd like for it to refresh the current page kinda.. with the html preview at the bottom.. kinda like

http://www.practiceboard.com
__________________
Porch Monkey. And that's the truth.
iqchicken is offline
Reply With Quote
View Public Profile Visit iqchicken's homepage!
 
Old 05-21-2006, 10:09 PM Re: From text box to HTML preview
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Wireless Audio
Posts: 2,314
Name: Keith Marshall
Location: West Hartford, CT
This type of method is built by a server-side script (such as php or asp) witch just resubmits the form to itself, the the server is parsing a script that translates the user input into the html output of the entire page.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 05-21-2006, 10:35 PM Re: From text box to HTML preview
Super Talker

Posts: 104
Location: San Diego, Ca
so the form action in this is what does it? i tried to test it out locally.. but I guess I would have to do this on a php enabled server or something eh?

Quote:
<?php
$Fname = $_POST["Fname"];
$Lname = $_POST["Lname"];
$gender = $_POST["gender"];
$food = $HTTP_POST_VARS["food"];
$quote = $_POST["quote"];
$education = $_POST["education"];
$TofD = $_POST["TofD"];
?>
<html>
<head>
<title>Personal INFO</title>
</head>
<body>
<form method="post" action="<?php echo $PHP_SELF;?>">
First Name:<input type="text" size="12" maxlength="12" name="Fname"><br />
Last Name:<input type="text" size="12" maxlength="36" name="Lname"><br />
Gender:<br />
Male:<input type="radio" value="Male" name="gender"><br />
Female:<input type="radio" value="Female" name="gender"><br />
Please choose type of residence:<br />
Steak:<input type="checkbox" value="Steak" name="food[]"><br />
Pizza:<input type="checkbox" value="Pizza" name="food[]"><br />
Chicken:<input type="checkbox" value="Chicken" name="food[]"><br />
<textarea rows="5" cols="20" name="quote" wrap="physical">Enter your favorite quote!</textarea><br />
Select a Level of Education:<br />
<select name="education">
<option value="Jr.High">Jr.High</option>
<option value="HighSchool">HighSchool</option>
<option value="College">College</option></select><br />
Select your favorite time of day:<br />
<select name="TofD" size="3">
<option value="Morning">Morning</option>
<option value="Day">Day</option>
<option value="Night">Night</option></select><br />
<input type="submit" value="submit" name="submit">
</form>
__________________
Porch Monkey. And that's the truth.
iqchicken is offline
Reply With Quote
View Public Profile Visit iqchicken's homepage!
 
Old 05-21-2006, 10:59 PM Re: From text box to HTML preview
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Wireless Audio
Posts: 2,314
Name: Keith Marshall
Location: West Hartford, CT
Correct
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 05-21-2006, 11:48 PM Re: From text box to HTML preview
Novice Talker

Posts: 13
Location: Vancouver, BC
try this:

HTML Code:
<html>
<head>
<script language="JavaScript">
function previewHtml() {
var textarea = document.getElementById('source');
var srcText = textarea.value;
var viewDiv = document.getElementById('view');
viewDiv.innerHTML = srcText;
}
</script>
</head>
<body>
<textarea id="source" style="width:100%;height:250px"><b>enter html here</b></textarea>
<input type="button" value="preview html" onClick="previewHtml()">
<hr>
<div id="view"></div>
</body>
</html>
__________________
Visit my startup - Tooldle.com: $0 Web Plugin Tools for Web Designer

Last edited by gumlor : 05-22-2006 at 12:02 AM.
gumlor is offline
Reply With Quote
View Public Profile
 
Old 05-22-2006, 12:17 AM Re: From text box to HTML preview
Ultra Talker

Posts: 252
Location: Auckland, New Zealand
I recommend against not using innerHTML as it is IE specific although Firefox does support this too not all browsers do, it's not standard, you have to use proper DOM creation to do such a thing so that it is known to the DOM document.

Another thing is the input element requires it to be inside a form, only if using XHTML 2.0 and XForms would this be possible but IE does not support this yet, nor do they say when they will.

I would suggest using a serverside language, as you can not secure the type of input effectively using javascript which would be a big concern if you allowed this.

You do require a PHP enabled web server for your code, and what you've written from what I've looked at so far, I can tell you that you'll receive a lot of errors and warnings.

You could quickly write something like this if you ignore the security concerns of it, it's not a tough project at all.

Cheers,

MC
__________________
#------------------------------signature---------------------------------------------------------------------------------#
Quote:
I am well recognised for what I don't do than what I do. Chores are just one of those things.
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Old 05-22-2006, 11:21 AM Re: From text box to HTML preview
Super Talker

Posts: 104
Location: San Diego, Ca
well ok.. so i'll get a bunch of errrors.. lol.. well the biggest error of all is that I'm not sure how to get even the basic idea of a php-self form. I have tried that code (which is from a tutorial site on the subject) on a php enabled server and it simply refreshes the page and clears the contents of the form. I'm not sure what's wrong. I'm a complete noob, but attemtping to learn.

security will be more of an issue when i get to your level of knowledge on the subject
__________________
Porch Monkey. And that's the truth.

Last edited by iqchicken : 05-22-2006 at 11:28 AM.
iqchicken is offline
Reply With Quote
View Public Profile Visit iqchicken's homepage!
 
Reply     « Reply to From text box to HTML preview
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14979 seconds with 13 queries