Javascript setHTML() won't set editor to a null value

Last post 06-07-2007, 5:30 PM by DanC. 3 replies.
Sort Posts: Previous Next
  •  06-06-2007, 1:02 PM 30445

    Javascript setHTML() won't set editor to a null value

    I have an editor on a form created server side with the following code:
     
          CommentEditor.ID = "TaskCodeComment"
          CommentEditor.Text = sCurrentComment
          CommentEditor.FilesPath = "ce/CuteEditor_Files"
          CommentEditor.EditorBodyStyle = "font:normal 12px arial;"
          CommentEditor.EditorWysiwygModeCss = "asp.css"
          CommentEditor.ConfigurationPath = "ce/CuteEditor_Files/Configuration/dossier.config"
          CommentEditor.UseHTMLEntities = false
          CommentEditor.BreakElement = "Br"
          CommentEditor.ShowBottomBar = false
          CommentEditor.Width = "100%"
          CommentEditor.CustomAddons = "<img title=""Save Comments"" class=""CuteEditorButton"" onmouseover=""CuteEditor_ButtonCommandOver(this)"" onmouseout=""CuteEditor_ButtonCommandOut(this)"" onmousedown=""CuteEditor_ButtonCommandDown(this)"" onmouseup=""CuteEditor_ButtonCommandUp(this)"" ondragstart=""CuteEditor_CancelEvent()"" Command=""SaveComment"" src=""ce/CuteEditor_Files/images/save.gif"" />"
          CommentEditor.Draw()
    Through Javascript, it displays text retrieved from a database when a drop down is changed.  Depending on the item selected in the drop down, an item may or may not have text.  If it does, using the javascript API, I use editor.setHTML(sText) to update the editor window with the text.
     
    This works fine.  It's when there isn't any text that I have the problem.  editor.setHTML('') doesn't work.  The text in the editor remains.  I created 2 test buttons to test this functionality
     
    This line works
    <input type="button" value="Click" onclick="document.getElementById('CE_TaskCodeComment_ID').setHTML('DAN');alert(document.getElementById('CE_TaskCodeComment_ID').getHTML())"
    />
    It sets the content of the editor to DAN.  The alert box displays DAN as well.
     
    This line does not work.
    <input type="button" value="Click" onclick="document.getElementById('CE_TaskCodeComment_ID').setHTML('');alert(document.getElementById('CE_TaskCodeComment_ID').getHTML())" />
     
    The previous text that was in the editor (in this case DAN) remains in the box and the alert displays DAN as well.
     
    I've tried various renditions of trying to do this but none work.  This includes trying the above from within a called javascript function and setting a variable to the editor object and calling editor.setHTML(sSomeText).  Nothing works.
     
    Anyone have any idea?
  •  06-06-2007, 1:40 PM 30447 in reply to 30445

    Re: Javascript setHTML() won't set editor to a null value

    Dan,
     
    Which version of Cute Editor are you using?
     
    Can you try the SetHTML function in the following example?
     
     
    The source code of this example can be found in the download package.
     
    Hope it helps. Let me know if you have any further questions.
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  06-07-2007, 4:34 PM 30496 in reply to 30447

    Re: Javascript setHTML() won't set editor to a null value

    I'm using Version 6, my boss just bought it a few weeks ago.
     
    OK, So the sample worked.  So then I started taking out anything that wasn't part of the code for the sample.  When I removed my custom config file, setHTML() worked.  Odd though that it did.  Not sure why.  I'm used to using the disabled items string anyway, the version I have on another server of my own is Ver 3.  (Yeah, one of these days I will upgrade).
     
    But I also have a problem with all the buttons on the toolbars and with the bottom bar.  None of the toolbar buttons work. If I press them, they do flash, so the mousedown event is probably firing or something.  On the bottom bar, I can't switch views and expand/collapse don't work either.  So I went back again and I started with the sample.  I'm down to what I think is the minimum needed to get an editor to run.
     
          CommentEditor.ID = "TaskCodeComment"
          CommentEditor.Text = sCurrentComment
          CommentEditor.FilesPath = "ce/CuteEditor_Files"
          CommentEditor.AutoConfigure = "Default"
          CommentEditor.Draw()
    The ce folder is the root of the Zip file.
     
    Not sure what is happening or where to look at this point.
  •  06-07-2007, 5:30 PM 30502 in reply to 30496

    Re: Javascript setHTML() won't set editor to a null value

    This was a doozy to figure out.  I finally ripped out all my client side script and the minimal config worked.  So I started placing my script back in, one function at a time.  I had a custom button on the toolbar.  ANd I guess regardless of the configuration, you call

    CuteEditor_OnCommand

     
    The problem was that my script handles 2 different editors on the same page.  The problem wasn't the 2 editors or the 2 custom buttons, since both buttons only do some stuff and both returned true, I saved a line of code by returning true at the end of the function.  Little did I know that the function needs to return false if my commands are not handled because another button is pressed.  When I moved the return true to inside the if {} constructs for each of my button handlers, everything worked as it should have.
     
    Now I just have to go out there and put everything else I ripped or changed out back in the code!  Argh.  You may want to add that someplace in the documentation, that a custom button handler needs to return false if it doesn't handle the custom buttons.
View as RSS news feed in XML