Rich Text Form in JavaScript gives error: Object required

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • IkBenHet

    Rich Text Form in JavaScript gives error: Object required

    Hello,

    I found this script to create a simple rich text form
    (http://programmabilities.com/xml/index.php?id=17):

    <html>
    <head>
    <title>Rich Text Editor</title>
    </head>
    <body>
    <script language= "JavaScript " type= "text/javascript" src=
    "editor.js" >
    //First lets initiate some variables

    var isEditable= false;
    var isIE;
    var isGecko;
    var isSafari;
    var isKonqueror;

    function initiateEditor( ) {
    //check what browser is in use
    var browser = navigator.userA gent.toLowerCas e();
    isIE = ((browser .indexOf("msie" ) != -1) && (browser
    ..indexOf("oper a") == -1) && (browser .indexOf("webtv ") == -1));
    isGecko = (browser .indexOf("gecko ") != -1);
    isSafari = (browser .indexOf("safar i") != -1);
    isKonqueror = (browser.indexO f("konqueror" ) != -1);

    //enable designMode if the browser is not safari or konqueror.
    if (document.getEl ementById && document.design Mode && !isSafari &&
    !isKonqueror) {
    isEditable= true;
    }
    }
    //Javascript function dislpayEditor will create the textarea.

    function displayEditor(e ditor, html, width, height) {
    if(isEditable){
    document.writel n('<iframe id="' + editor + '" name="' + editor
    + '" width="' + width + 'px" height="' + height + 'px"></iframe>');
    //create a hidden field that will hold everything that is typed in the
    textarea
    document.writel n('<input type="hidden" id="hidden' + editor +
    '" name="hidden' + editor + '" value="">');
    //assign html (textarea value) to hiddeneditor
    document.getEle mentById('hidde n' + editor).value = html;
    //call function designer
    designer(editor , html);
    }else{
    document.writel n('<textarea name="' + editor + '" id="' + editor
    + '" cols="39" rows="10">' + html + '</textarea>');
    }
    }

    //this is designer function that enables designMode and writes defalut
    text to the text area
    function designer(editor , html) {
    var mainContent= "<html id=" + editor + "><head></head><body>" +
    html + "</body></html>" ;
    //assign the frame(textarea) to the edit variable using that frames id
    var edit= document.getEle mentById(editor ).contentWindow .document;
    //write the content to the textarea
    edit.write(main Content);
    //enable the designMode
    edit.designMode = "On" ;
    document.getEle mentById(conten t).contentDocum ent.designMode = "on";
    }

    //To execute command we will use javascript function editorCommand.
    function editorCommand(e ditor, command, option) {
    // first we assign the content of the textarea to the variable
    mainField
    var mainField;
    mainField = document.getEle mentById(editor ).contentWindow ;
    // then we will use execCommand to execute the option on the textarea
    making sure the textarea stays in focus
    try {
    mainField.focus ();
    mainField.docum ent.execCommand (command, false, option);
    mainField.focus ();
    } catch (e) { }
    }

    function updateEditor(ed itor) {
    if (!isEditable) return;
    //assign the value of the textarea to the hidden field.
    var hiddenField = document.getEle mentById('hidde n' + editor);
    if (hiddenField.va lue == null) hiddenField.val ue = "";
    hiddenField.val ue =
    document.getEle mentById(editor ).contentWindow .document.body. innerHTML;
    }
    </script>
    <table width="750">
    <form action="form.as p" name="edit" method="POST" id="edit"
    onsubmit="retur n submitForm();">
    <tr>
    <td> <a href= "javascript:edi torCommand('con tent', 'bold', '')" ><img
    src="bold.gif" width="25" height="24" alt="Bold" title="Bold"
    border="0"></a> </td>

    <td> <a href= "javascript:edi torCommand('con tent', 'underline', '')"[color=blue]
    ><img src="underline. gif" width="25" height="24" alt="Underline" title="Underlin e" border="0"></a> </td>[/color]

    <td> <a href= "javascript:edi torCommand('con tent', 'italic', '')"[color=blue]
    ><img src="italic.gif " width="25" height="24" alt="Italic" title="Italic" border="0"></a> </td>[/color]

    <td> <a href= "javascript:edi torCommand('con tent', 'justifyleft', '')"[color=blue]
    ><img src="j_left.gif " width="25" height="24" alt="Align Left" title="Align Left" border="0"></a> </td>[/color]

    <td> <a href= "javascript:edi torCommand('con tent', 'justifycenter' ,
    '')" ><img src="j_center.g if" width="25" height="24" alt="Align Center"
    title="Align Center" border="0"></a> </td>

    <td> <a href= "javascript:edi torCommand('con tent', 'justifyright',
    '')" ><img src="j_right.gi f" width="25" height="24" alt="Align Right"
    title="Align Right" border="0"></a> </td>

    <td> <a href= "javascript:edi torCommand('con tent', 'indent', '')"[color=blue]
    ><img src="indent.gif " width="25" height="24" alt="Indent" title="Indent" border="0"></a> </td>[/color]

    <td> <a href= "javascript:edi torCommand('con tent', 'outdent', '')"[color=blue]
    ><img src="outdent.gi f" width="25" height="24" alt="Outdent" title="Outdent" border="0"></a> </td>[/color]

    <td> <a href= "javascript:edi torCommand('con tent', 'undo', '')" ><img
    src="undo.gif" width="25" height="24" alt="Undo" title="Undo"
    border="0"></a> </td>

    <td> <a href= "javascript:edi torCommand('con tent', 'redo', '')" ><img
    src="redo.gif" width="25" height="24" alt="Redo" title="Redo"
    border="0"></a> </td>

    <td width="100%" align="levt">Sh ift+Enter for single line spacing</td>
    </tr>
    <tr>
    <td colspan="12">
    <script language="JavaS cript" type="text/javascript">
    <!--
    function submitForm() {
    updateEditor('c ontent');
    //alert("content = " + document.edit.h iddencontent.va lue);
    return true;
    }

    initiateEditor( );
    //-->
    </script>
    <script language="JavaS cript" type="text/javascript">
    <!--
    displayEditor(' content', '', 600, 300);
    //-->
    </script>
    </td>
    </tr>
    <tr><td colspan="12"> <input type="submit" name="Submit"
    value="Submit"> </td></tr>
    </form>
    </table>

    </body>
    </html>


    But it is giving me this error in the status bar of my IE:
    Line: 48
    Char: 4
    Error: Object required
    Code: 0
    URL: http://bewebmaster.com/editorjs/

    Can somebody please help me out on this?

    Thanks

  • IkBenHet

    #2
    Re: Rich Text Form in JavaScript gives error: Object required

    Hello,

    What is actually the use of this line:
    document.getEle mentById(conten t).contentDocum ent.designMode = 'On';

    Because when I mark it out it is still working!

    Sorry but I am new in JavaScript.

    Thanks

    IkBenHet schreef:[color=blue]
    > Hello,
    >
    > I found this script to create a simple rich text form
    > (http://programmabilities.com/xml/index.php?id=17):
    >
    > <html>
    > <head>
    > <title>Rich Text Editor</title>
    > </head>
    > <body>
    > <script language= "JavaScript " type= "text/javascript" src=
    > "editor.js" >
    > //First lets initiate some variables
    >
    > var isEditable= false;
    > var isIE;
    > var isGecko;
    > var isSafari;
    > var isKonqueror;
    >
    > function initiateEditor( ) {
    > //check what browser is in use
    > var browser = navigator.userA gent.toLowerCas e();
    > isIE = ((browser .indexOf("msie" ) != -1) && (browser
    > .indexOf("opera ") == -1) && (browser .indexOf("webtv ") == -1));
    > isGecko = (browser .indexOf("gecko ") != -1);
    > isSafari = (browser .indexOf("safar i") != -1);
    > isKonqueror = (browser.indexO f("konqueror" ) != -1);
    >
    > //enable designMode if the browser is not safari or konqueror.
    > if (document.getEl ementById && document.design Mode && !isSafari &&
    > !isKonqueror) {
    > isEditable= true;
    > }
    > }
    > //Javascript function dislpayEditor will create the textarea.
    >
    > function displayEditor(e ditor, html, width, height) {
    > if(isEditable){
    > document.writel n('<iframe id="' + editor + '" name="' + editor
    > + '" width="' + width + 'px" height="' + height + 'px"></iframe>');
    > //create a hidden field that will hold everything that is typed in the
    > textarea
    > document.writel n('<input type="hidden" id="hidden' + editor +
    > '" name="hidden' + editor + '" value="">');
    > //assign html (textarea value) to hiddeneditor
    > document.getEle mentById('hidde n' + editor).value = html;
    > //call function designer
    > designer(editor , html);
    > }else{
    > document.writel n('<textarea name="' + editor + '" id="' + editor
    > + '" cols="39" rows="10">' + html + '</textarea>');
    > }
    > }
    >
    > //this is designer function that enables designMode and writes defalut
    > text to the text area
    > function designer(editor , html) {
    > var mainContent= "<html id=" + editor + "><head></head><body>" +
    > html + "</body></html>" ;
    > //assign the frame(textarea) to the edit variable using that frames id
    > var edit= document.getEle mentById(editor ).contentWindow .document;
    > //write the content to the textarea
    > edit.write(main Content);
    > //enable the designMode
    > edit.designMode = "On" ;
    > document.getEle mentById(conten t).contentDocum ent.designMode = "on";
    > }
    >
    > //To execute command we will use javascript function editorCommand.
    > function editorCommand(e ditor, command, option) {
    > // first we assign the content of the textarea to the variable
    > mainField
    > var mainField;
    > mainField = document.getEle mentById(editor ).contentWindow ;
    > // then we will use execCommand to execute the option on the textarea
    > making sure the textarea stays in focus
    > try {
    > mainField.focus ();
    > mainField.docum ent.execCommand (command, false, option);
    > mainField.focus ();
    > } catch (e) { }
    > }
    >
    > function updateEditor(ed itor) {
    > if (!isEditable) return;
    > //assign the value of the textarea to the hidden field.
    > var hiddenField = document.getEle mentById('hidde n' + editor);
    > if (hiddenField.va lue == null) hiddenField.val ue = "";
    > hiddenField.val ue =
    > document.getEle mentById(editor ).contentWindow .document.body. innerHTML;
    > }
    > </script>
    > <table width="750">
    > <form action="form.as p" name="edit" method="POST" id="edit"
    > onsubmit="retur n submitForm();">
    > <tr>
    > <td> <a href= "javascript:edi torCommand('con tent', 'bold', '')" ><img
    > src="bold.gif" width="25" height="24" alt="Bold" title="Bold"
    > border="0"></a> </td>
    >
    > <td> <a href= "javascript:edi torCommand('con tent', 'underline', '')"[color=green]
    > ><img src="underline. gif" width="25" height="24" alt="Underline" title="Underlin e" border="0"></a> </td>[/color]
    >
    > <td> <a href= "javascript:edi torCommand('con tent', 'italic', '')"[color=green]
    > ><img src="italic.gif " width="25" height="24" alt="Italic" title="Italic" border="0"></a> </td>[/color]
    >
    > <td> <a href= "javascript:edi torCommand('con tent', 'justifyleft', '')"[color=green]
    > ><img src="j_left.gif " width="25" height="24" alt="Align Left" title="Align Left" border="0"></a> </td>[/color]
    >
    > <td> <a href= "javascript:edi torCommand('con tent', 'justifycenter' ,
    > '')" ><img src="j_center.g if" width="25" height="24" alt="Align Center"
    > title="Align Center" border="0"></a> </td>
    >
    > <td> <a href= "javascript:edi torCommand('con tent', 'justifyright',
    > '')" ><img src="j_right.gi f" width="25" height="24" alt="Align Right"
    > title="Align Right" border="0"></a> </td>
    >
    > <td> <a href= "javascript:edi torCommand('con tent', 'indent', '')"[color=green]
    > ><img src="indent.gif " width="25" height="24" alt="Indent" title="Indent" border="0"></a> </td>[/color]
    >
    > <td> <a href= "javascript:edi torCommand('con tent', 'outdent', '')"[color=green]
    > ><img src="outdent.gi f" width="25" height="24" alt="Outdent" title="Outdent" border="0"></a> </td>[/color]
    >
    > <td> <a href= "javascript:edi torCommand('con tent', 'undo', '')" ><img
    > src="undo.gif" width="25" height="24" alt="Undo" title="Undo"
    > border="0"></a> </td>
    >
    > <td> <a href= "javascript:edi torCommand('con tent', 'redo', '')" ><img
    > src="redo.gif" width="25" height="24" alt="Redo" title="Redo"
    > border="0"></a> </td>
    >
    > <td width="100%" align="levt">Sh ift+Enter for single line spacing</td>
    > </tr>
    > <tr>
    > <td colspan="12">
    > <script language="JavaS cript" type="text/javascript">
    > <!--
    > function submitForm() {
    > updateEditor('c ontent');
    > //alert("content = " + document.edit.h iddencontent.va lue);
    > return true;
    > }
    >
    > initiateEditor( );
    > //-->
    > </script>
    > <script language="JavaS cript" type="text/javascript">
    > <!--
    > displayEditor(' content', '', 600, 300);
    > //-->
    > </script>
    > </td>
    > </tr>
    > <tr><td colspan="12"> <input type="submit" name="Submit"
    > value="Submit"> </td></tr>
    > </form>
    > </table>
    >
    > </body>
    > </html>
    >
    >
    > But it is giving me this error in the status bar of my IE:
    > Line: 48
    > Char: 4
    > Error: Object required
    > Code: 0
    > URL: http://bewebmaster.com/editorjs/
    >
    > Can somebody please help me out on this?
    >
    > Thanks[/color]

    Comment

    Working...