Categories
Advertisement
... New Photos
How to build a live comment preview with Javascript and HTML
In recent times, it has become quite a trendy and nifty trick to show a live comment preview on a lot of blog websites. I remember just how excited i was the first time i saw this in action on a dotnet blogengine application. In this article i will show you how to implement a live comment preview on your website with just simple javascript and HTML.
Okay, to get started i will start by creating a javascript(.js) file with the following on it.
function ShowCommentPreview()
{
// Access the HTML elements we care about from our page
var enteredCommentName = document.getElementById("CommentName");
var previewCommentName = document.getElementById("CommentPreviewName");
var enteredComment = document.getElementById("CommentBody");
var previewComment = document.getElementById("CommentPreviewBody");
// Let javascript do it's final bit of magic
previewCommentName.innerHTML = enteredCommentName.value + " Says: ";
previewComment.innerHTML = enteredComment.value;
}
As you can see the javascript is almost self explanatory. First, I declared variables and i assigned various id's of the HTML elements i cared about to them from our page. Finally i take the value of the entered comment and placed it as the value of the comment preview.
Some of the HTML
<textarea id="CommentBody"></textarea>
Finally, i added a HTML Onclick attribute with the Javascript function call to the textarea to wire up the HTML and the javascript method together for the final trick.
That's it ... pretty easy thing to do. I hope you will enjoy building it on your own website. Good luck.
Download the sample file live-comment-preview.zip (4KB)
Comments
-
Joshua, wrote:24 February 2008 (4 years ago)These are great..
-
free icons from United States, North America wrote:20 March 2008 (4 years ago)Great icons resources, Can you add my free icons site to your list
http://www.freeiconsdownload.com
Thanks -
mr.eims from Kuala Lumpur, Malaysia wrote:5 April 2008 (4 years ago)i thought it can be downloaded in an arcived file. anyway..many thanks though.. :D
-
nkhat from Saudi Arabia, Asia wrote:8 May 2008 (4 years ago)wow 500 :) , thank you my friend :), good luck .
-
-
Seanau from North America wrote:20 June 2008 (4 years ago)Need high quality free and commercial icons?
Vistit out website now: http://www.seanau.com -
-
PHL parking from North America, World wrote:21 July 2010 (2 years ago)Awesome, thanks for the free icons
-
-
Fade from Asia, World wrote:16 January 2011 (1 year ago)Cooolll! ... like... :)-m-m
-
Byggeri , wrote:3 September 2011 (5 months ago)I really enjoy this theme you've got going on in your web page. What is the name of the template by the way? I was thinking of using this style for the site I am going to construct for my school project.
-
SEO Company Toronto from fsd wrote:8 September 2011 (5 months ago)Thank you for this post. Thats all I are able to say. You most absolutely have built this blog website into something speciel. You clearly know what you are working on, youve insured so many corners.thanks
-
aso ankle braces from granby wrote:29 September 2011 (4 months ago)I just wonder how did you make the sculpture that can be seen in the picture's above, it really attract my attention, very nice masterpiece.
-
pmp exam prep from Gambia, Africa wrote:1 October 2011 (4 months ago)Thanks for sharing this free icons , I will choose one for my website, thanks
-
brachial plexus injuries , wrote:20 November 2011 (3 months ago)You produce a great point in your own final paragraph. We couldn’t agree more together with your points. In today’s modern world, your approach to this issue is lacking in today’s kids. We need to ensure that our kids find out more on this topic so we never lose our ways
-
personal injury Ireland from pakistan wrote:2 December 2011 (2 months ago)these 500 icons are much beter than the other blogs provides. thanks. it add beauty to my website.
RSS feed for comments on this page | RSS feed for all comments