ASP
  Home arrow ASP arrow Page 4 - Building a WYSIWYG HTML Editor Part 2/2
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Building a WYSIWYG HTML Editor Part 2/2
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 61
    2002-04-12

    Table of Contents:
  • Building a WYSIWYG HTML Editor Part 2/2
  • Creating the database
  • Implementing the WYSIWYG HTML editor
  • Implementing the WYSIWYG HTML editor (contd.)
  • Displaying the news posts
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Building a WYSIWYG HTML Editor Part 2/2 - Implementing the WYSIWYG HTML editor (contd.)


    (Page 4 of 6 )

    I've also included the following code at the top of the page:

    <!-- #INCLUDE file="db.asp" -->
    <% dim objConn dim objRS set objConn = Server.CreateObject("ADODB.Connection") set objRS = Server.CreateObject("ADODB.Recordset")
    objConn.Open dbConnString
    objRS.ActiveConnection = objConn %>


    Our newsposts.asp file now contains all of the fields we need for our news posts: title, author, topic(s) and content. It looks like this:

     Our revamped news form

    The <form> element that we added to newsposts.asp looks like this:

    <form onSubmit="return ProcessNews()" name="frmNews" action="newsposts.asp" method="post">


    As you can see, the action attribute means that all data from the form will be sent back to the same page, newsposts.asp. We need a way to tell whether or not we should display the news form or actually add the news to our SQL Server database, and the hidden form variable action gives us all of the info we need:

    <input type="hidden" name="action" value="addNews">

    If action is equal to addNews then we add the news to the database. If not, we display the news form…simple. At the top of newsposts.asp, just under the code that connects to our database, we add the following code that separates newsposts.asp into two separate sub-routines:

    dim action action = Request.Form("action")
    if action = "addNews" then
    addNews()
    else
    showNewsForm()
    end if
    sub showNewsForm()
     'HTML Code for news form goes below %>
    <% end sub
    sub addNews()
    dim author
    dim title
    dim topics
    dim newsPost
    author = Request.Form("author")
    title = Replace(Request.Form("title"), "'", "''")
    topics = Request.Form("topics")
    newsPost = Replace(Request.Form("newsPost"), "'", "''")
    objConn.Execute "insert into newsPosts(title,topics,newsPost,authorId) values('" & title & "', '" & topics & "','" & newsPost & "'," & author & ")"
    Response.Write "<b>New news post added OK, here's what you added:<br><br></b>" Response.Write Request.Form("newsPost")
    objConn.Close
    set objConn = nothing
    end sub
    %>


    Refresh newsposts.asp and complete the form. You'll notice that if you leave any fields blank or not selected that a dialog box will popup telling you to complete the empty fields. JavaScript isn't the best form of data validation, however we’re already making heavy use of JavaScript for our HTML editor so I thought I would continue with it. In a production environment you would of course implement server side error handling and data validation techniques in the addNews sub-routine. The addNews sub-routine adds our news to the newsPosts table and also shows us a preview of the news once it's been added, like this:

    Adding a news posts and previewing it 

    In the example above I've copy-pasted directly from socket6.com into the WYSIWYG editor, in fact, I could even copy-paste straight from Microsoft Word if I wanted to!

    More ASP Articles
    More By Mitchell Harper


       · the [iframename].document.body.innerhtml removes all quotations from id values.I...
       · I cannot get the iFrame contents to post into my database. Perhaps it is because I...
     

    ASP ARTICLES

    - Central Scoreboard with Flash and ASP
    - Calorie Counter Using WAP and ASP
    - Creating PGP-Encrypted E-Mails Using ASP
    - Be My Guest in ASP
    - Session Replacement in ASP
    - Securing ASP Data Access Credentials Using t...
    - The Not So Ordinary Address Book
    - Adding and Displaying Data Easily via ASP an...
    - Sending Email From a Form in ASP
    - Adding Member Services in ASP
    - Removing Unconfirmed Members
    - Trapping HTTP 500.100 - Internal Server Error
    - So Many Rows, So Little Time! - Case Study
    - XDO: An XML Engine Class for Classic ASP
    - Credit Card Fraud Prevention Using ASP and C...







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 8 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek