Advertisement

01.09.2003 at 02:46AM PST, ID: 20449446
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

html editor made in javascript under IE

Asked by boig in JavaScript, Macromedia Homesite

Tags:

I found an html editor made in javascript which work ok under IE. Now I am trying to integrate it into a form in order to make my personal website message board prettier and easyier to use. I work with php and mysql, but I don't know how to send the text. here is the code:

<HTML>
<HEAD>
<TITLE>HTML editor</TITLE>
<script LANGUAGE="JavaScript"> <!--
_version=10; //--> </script>
<script LANGUAGE="JavaScript1.1"> <!--
_version=11; // --> </script>
<script LANGUAGE="JavaScript">
<!--
// -->
</SCRIPT>

</center><script language="JavaScript">
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
var browser=((document.layers || document.all) && parseInt(navigator.appVersion)>=4 && !(document.all && navigator.userAgent.indexOf("Mac")>-1))

var numAttachments=0;
function getfilename( ){
      document.composeForm.filename.value="";
      document.composeForm.filename.value=document.composeForm.attachment.value;;
      return;
}
function getaddress(ur1){
      window.open(ur1,'getaddress','width=300,height=450,resizable=yes,scrollbars=yes');
}
function checkFields( ){
      var ret1;
      var ret2;
      if(document.composeForm.to.value.length==0) {
            alert("Please enter an email address");
            return false ;
      }
}
function attachAttachment() {
  var maxNumAttachments = 5;

  if (numAttachments == maxNumAttachments){
    alert("You can have a maximum of"
          + maxNumAttachments + "attachments");
  }
  if (document.composeForm.attachment.value == "") {
    alert("No file has been selected");
  } else {
    getfilename();
    document.composeForm.att.value="upload";
          sendHtml();
    document.composeForm.submit();
  }
}

function removeAttachment() {
  var index=document.composeForm.attachmentlists.options.selectedIndex;
  if (index>=1) {
    document.composeForm.att.value="del";
      sendHtml();
    document.composeForm.submit();
  } else {
    alert("You did not select an attachments to remove");
  }
}


var bLoad=false
var pureText=true
var bodyTag="<BODY>"
var bTextMode=false

public_description=new Editor

/*****************************
 Power Editor class
 member function:
 SetHtml
 GetHtml
 SetText
 GetText
 GetCompFocus()
 *****************************/
function Editor() {
  this.put_html=SetHtml;
  this.get_html=GetHtml;
  this.put_text=SetText;
  this.get_text=GetText;
  this.CompFocus=GetCompFocus;
}

function GetCompFocus() {
  Composition.focus();
}

function GetText() {
  return Composition.document.body.innerText;
}

function SetText(text) {
  text = text.replace(/\n/g, "<br>")
  Composition.document.body.innerHTML=text;
}

function GetHtml() {
  if (bTextMode)
    return Composition.document.body.innerText;
  else {
    cleanHtml();
    cleanHtml();
    return Composition.document.body.innerHTML;
  }
}

function SetHtml(sVal) {
  if (bTextMode) Composition.document.body.innerText=sVal;
  else Composition.document.body.innerHTML=sVal;
}
//End  of Editor Class

/***********************************************
 Initialize everything when the document is ready
 ***********************************************/
var YInitialized = false;
function document.onreadystatechange() {
      if (YInitialized) return;
      YInitialized = true;
        istexthtml = "yes";
      Composition.document.open()
      Composition.document.write("<BODY></body>");
      Composition.document.close()
      Composition.document.designMode="On"

      if (istexthtml == "yes") {
            public_description.put_html(document.composeForm.composebody.value);
      }
      else{
            public_description.put_text(document.composeForm.composebody.value);
      }
}

// Check if toolbar is being used when in text mode
function validateMode() {
  if (! bTextMode) return true;
  alert("Please uncheck the \"View HTML source\" checkbox to use the toolbars");
  Composition.focus();
  return false;
}

function sendHtml(){
      if(bTextMode){
            document.composeForm.body.value = public_description.get_text();
      }
      else{
            document.composeForm.body.value = public_description.get_html();

      }
      if(document.composeForm.switchnow.value=="yes"){
            document.composeForm.body.value = document.composeForm.body.value.replace(/<BR>/g, "\n");
      }
      return true;
}

//Formats text in composition.
function formatC(what,opt) {
  if (!validateMode()) return;
 
  if (opt=="removeFormat") {
    what=opt;
    opt=null;
  }

  if (opt==null) Composition.document.execCommand(what);
  else Composition.document.execCommand(what,"",opt);
 
  pureText = false;
  Composition.focus();
}

//Switches between text and html mode.
function setMode(newMode) {
  bTextMode = newMode;
  var cont;
  if (bTextMode) {
    cleanHtml();
    cleanHtml();

    cont=Composition.document.body.innerHTML;
    Composition.document.body.innerText=cont;
  } else {
    cont=Composition.document.body.innerText;
    Composition.document.body.innerHTML=cont;
  }
 
  Composition.focus();
}

//Finds and returns an element.
function getEl(sTag,start) {
  while ((start!=null) && (start.tagName!=sTag)) start = start.parentElement;
  return start;
}

function createLink() {
  if (!validateMode()) return;
 
  var isA = getEl("A",Composition.document.selection.createRange().parentElement());
  var str=prompt("Enter url:", isA ? isA.href : "http:\/\/");
 
  if ((str!=null) && (str!="http://")) {
    if (Composition.document.selection.type=="None") {
      var sel=Composition.document.selection.createRange();
      sel.pasteHTML("<A HREF=\""+str+"\">"+str+"</A> ");
      sel.select();
    }
    else formatC("CreateLink",str);
  }
  else Composition.focus();
}

function cleanHtml() {
  var fonts = Composition.document.body.all.tags("FONT");
  var curr;
  for (var i = fonts.length - 1; i >= 0; i--) {
    curr = fonts[i];
    if (curr.style.backgroundColor == "#ffffff") curr.outerHTML = curr.innerHTML;
  }
}

function write_signature() {
      var signature = "";
      cf = document.composeForm;
      index = composeForm.signature.selectedIndex;

      if (cf.signature[index].value == 1) {
            signature = "";
      }
      else if (cf.signature[index].value == 2) {
            signature = "";
      }
      else if (cf.signature[index].value == 3) {
            signature = "";
      }
      else {
            return;
      }
      cf.body.value += '\r\n\r\n';
      cf.body.value += signature;

      if(bTextMode)
      {
            temp = public_description.get_text();
            temp += '\r\n\r\n';
            temp += signature;
            public_description.put_text(temp);
      }
      else
      {
            temp = public_description.get_html();
            temp += "<p>";
            temp += signature;
            public_description.put_html(temp);
      }
}
function confirmSwitch(){
      if(bTextMode){
            if(confirm('You have checked View HTML Source. Do you want to continue with the displayed text, including the HTML tags?')){
                  Composition.document.body.innerText=public_description.get_text();
                  document.composeForm.switchnow.value="yes";
                  return true;
            }
      }
      else{
            if(confirm('This will convert your message into plain text. All formatting will be lost. Continue?')){
                  Composition.document.body.innerText=public_description.get_text();
                  document.composeForm.switchnow.value="yes";
                  return true;
            }
      }
      return false;
}

function updateSaveSent(){
      dml = document.composeForm;
      if (dml.savesent_box.checked) {
            dml.savesent.value = "yes";
      }
      else {
            dml.savesent.value = "no";
        }
}
</script>


</HEAD>

<BODY BGCOLOR=#ffffff vlink=#0000ff>
<FORM ACTION='iproductos2.php' METHOD='post' ENCTYPE='multipart/form-data' name="composeForm" onSubmit="return sendHtml();">

<table cellpadding="5" cellspacing="0" border="0">

<tr><td>
<div class="yToolbar" ID="ParaToolbar">
  <div class="TBHandle"></div>
  <select ID="ParagraphStyle" class="TBGen" TITLE="Paragraph Format" LANGUAGE="javascript" onchange="formatC('formatBlock',this[this.selectedIndex].value);this.selectedIndex=0">
    <option class="heading" selected>Paragraph
    <option value="&lt;H1&gt;">Heading 1 &lt;H1&gt;
    <option value="&lt;H2&gt;">Heading 2 &lt;H2&gt;
    <option value="&lt;H3&gt;">Heading 3 &lt;H3&gt;
    <option value="&lt;H4&gt;">Heading 4 &lt;H4&gt;
    <option value="&lt;H5&gt;">Heading 5 &lt;H5&gt;
    <option value="&lt;H6&gt;">Heading 6 &lt;H6&gt;
    <option value="&lt;PRE&gt;">Formatted &lt;PRE&gt;
    <option value="removeFormat">Remove Formatting
  </select>
  <select ID="FontName" class="TBGen" TITLE="Font Name" LANGUAGE="javascript" onchange="formatC('fontname',this[this.selectedIndex].value);this.selectedIndex=0">
    <option class="heading" selected>Font
    <option value="Arial">Arial
    <option value="Arial Black">Arial Black
    <option value="Arial Narrow">Arial Narrow
    <option value="Comic Sans MS">Comic Sans MS
    <option value="Courier New">Courier New
    <option value="System">System
    <option value="Times New Roman">Times New Roman
    <option value="Verdana">Verdana
    <option value="Wingdings">Wingdings
  </select>
  <select ID="FontSize" class="TBGen" TITLE="Font Size" LANGUAGE="javascript" onchange="formatC('fontsize',this[this.selectedIndex].value);this.selectedIndex=0">
    <option class="heading" selected>Size
    <option value="1">1
    <option value="2">2
    <option value="3">3
    <option value="4">4
    <option value="5">5
    <option value="6">6
    <option value="7">7
  </select>
    <select ID="FontColor" class="TBGen" TITLE="Font Color" LANGUAGE="javascript" onchange="formatC('forecolor',this[this.selectedIndex].value);this.selectedIndex=0">
    <option class="heading" selected>Text Color
    <option value="red">red
    <option value="blue">blue
    <option value="green">green
    <option value="black">black
  </select>
   <select ID="FontBackColor" class="TBGen" TITLE="Font Back Color" LANGUAGE="javascript" onchange="formatC('backcolor',this[this.selectedIndex].value);this.selectedIndex=0">
    <option class="heading" selected>Text Background Color
    <option value="red">red
    <option value="blue">blue
    <option value="green">green
    <option value="black">black
    <option value="yellow">yellow
    <option value="">WHITE
  </select>
  <div class="TBSep"></div>
  <div ID="EditMode" class="TBGen" TITLE="Editing Mode">
    <input type=checkbox name="switchMode" LANGUAGE="javascript" onclick="setMode(switchMode.checked)">
      <font size="-1" color="#000000"><b>View HTML source</b> | </font>
      <a class="hlink" href="Javascript:formatC('formatBlock','removeFormat')"><b>Clear Format</b></a>
  </div>
</div>

<table><tr>
  <td><div class="Btn" TITLE="Cut" LANGUAGE="javascript" onclick="formatC('cut')">
    <img class="Ico" src="images/cut.gif">
  </div></td>
  <td><div class="Btn" TITLE="Copy"  LANGUAGE="javascript" onclick="formatC('copy')">
    <img class="Ico" src="images/copy.gif">
  </div></td>
  <td><div class="Btn" TITLE="Paste" LANGUAGE="javascript" onclick="formatC('paste')">
    <img class="Ico" src="images/paste.gif">
  </div></td>
  <td><div class="Btn" TITLE="Bold" LANGUAGE="javascript" onclick="formatC('bold');">
    <img class="Ico" src="images/bold.gif">
  </div></td>
  <td><div class="Btn" TITLE="Italic" LANGUAGE="javascript" onclick="formatC('italic')">
    <img class="Ico" src="images/italic.gif">
  </div></td>
  <td><div class="Btn" TITLE="Underline" LANGUAGE="javascript" onclick="formatC('underline')">
    <img class="Ico" src="images/under.gif">
  </div></td>
  <td><div class="Btn" TITLE="Align Left" NAME="Justify" LANGUAGE="javascript" onclick="formatC('justifyleft')">
    <img class="Ico" src="images/aleft.gif">
  </div></td>
  <td><div class="Btn" TITLE="Center" NAME="Justify" LANGUAGE="javascript" onclick="formatC('justifycenter')">
    <img class="Ico" src="images/center.gif">
  </div></td>
  <td><div class="Btn" TITLE="Align Right" NAME="Justify" LANGUAGE="javascript" onclick="formatC('justifyright')">
    <img class="Ico" src="images/aright.gif">
  </div></td>
  <td><div class="Btn" TITLE="Numbered List" LANGUAGE="javascript" onclick="formatC('insertorderedlist')">
    <img class="Ico" src="images/nlist.gif">
  </div></td>
  <td><div class="Btn" TITLE="Bulletted List" LANGUAGE="javascript" onclick="formatC('insertunorderedlist')">
    <img class="Ico" src="images/blist.gif">
  </div></td>
  <td><div class="Btn" TITLE="Decrease Indent" LANGUAGE="javascript" onclick="formatC('outdent')">
    <img class="Ico" src="images/ileft.gif">
  </div></td>
  <td><div class="Btn" TITLE="Increase Indent" LANGUAGE="javascript" onclick="formatC('indent')">
    <img class="Ico" src="images/iright.gif" >
  </div></td>
  <td><div class="Btn" TITLE="Create Hyperlink" LANGUAGE="javascript" onclick="createLink()">
    <img class="Ico" src="images/wlink.gif">
  </div></td>
  </tr></table>
<IFRAME class="Composition" width="100%" ID="Composition" height="190">
</IFRAME>
<SCRIPT>
<!--
Composition.document.open();
Composition.document.write(bodyTag);
Composition.document.close();
Composition.document.designMode="On";
// -->
</SCRIPT>
</td></tr>
</table>
<!-- fi de l'editor -->
</FORM>
</body></html>
Start Free Trial
[+][-]01.09.2003 at 07:43AM PST, ID: 7694634

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: JavaScript, Macromedia Homesite
Tags: javascript
Sign Up Now!
Solution Provided By: jdber
Participating Experts: 1
Solution Grade: B
 
 
[+][-]01.10.2003 at 12:43AM PST, ID: 7700337

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.10.2003 at 03:19AM PST, ID: 7700880

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44