This is a migrated thread and some comments may be shown as answers.

Why does this Javascript inside a custom Button Function not work?

1 Answer 39 Views
WebParts for SharePoint
This is a migrated thread and some comments may be shown as answers.
Yavuz Bogazci
Top achievements
Rank 1
Yavuz Bogazci asked on 27 Oct 2009, 02:53 PM
Hi all,

i have this custom Button function which works fine for me. Bu now i want to extend this function with one check. I want to check if the inserted Div already exists and stop processing.

Here is my code:

Telerik.Web.UI.Editor.CommandList["Inhaltsverzeichnis"] = function(commandName, editor, args)  
{  
  if (document.getElementById("toc")) {   
    alert('Es existiert bereits ein Inhaltsverzeichnis-Tag im Content-Bereich!');  
  }  
  else {   
    editor.pasteHtml('Inhaltsverzeichnis<br /><br /><div id="toc">-Inhaltsverzeichnis-</div><br /><br />');   
    alert('Inhaltsverzeichnis wurde erfolgreich hinzugefuegt!');  
  }  
};  

The div with the id = toc definitly exists, but my code always goes to the Else part of the if statement. Whats wrong?

thank you
yavuz

1 Answer, 1 is accepted

Sort by
0
Stanimir
Telerik team
answered on 27 Oct 2009, 03:19 PM
Hello Yavuz ,

The reason for this issue is that you need to use the document object of the RadEditor and not the one of the page where the editor is loaded.

For example:
If you are using RadEditor for MOSS 4.x
var doc  = editor.GetDocument();
doc.getElementById("toc");

If you are using RadEditor for MOSS 5.x
var doc  = editor.get_document();
doc.getElementById("toc");


Kind regards,
Stanimir
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
WebParts for SharePoint
Asked by
Yavuz Bogazci
Top achievements
Rank 1
Answers by
Stanimir
Telerik team
Share this question
or