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

Setting default text via Javascript

1 Answer 60 Views
WebParts for SharePoint
This is a migrated thread and some comments may be shown as answers.
Tom.S
Top achievements
Rank 1
Tom.S asked on 11 Dec 2008, 02:43 AM
Hi,
 I'm looking to add some text/html to a rad editor on page load.

The Rad Editor is being used on a NewForm.aspx page as a replacement for the default rich text editor. As the control is being added dynamically, i can't obtain a reference using the control name:

var editor = $find("<%=RadEditor1.ClientID%>"); 


So my approach is to traverse over the DOM and find the ID of the RAD editor control. I can do this successfully using the below javascript:

 

<script type="text/javascript">  
 
_spBodyOnLoadFunctionNames.push("fillDefaultValues");  
function fillDefaultValues() {  
 
 var oJobBrief = getTagFromIdentifierAndTitle("textarea""TextField""Job Brief");  
   
 var temp1 = oJobBrief.parentNode.previousSibling;   
 var oRadEditor = $find(temp1.id);  
 oRadEditor._contentArea.innerHTML = "test";  
 
 
}  
 
    function getTagFromIdentifierAndTitle(tagName, identifier, title) {  
 
      var len = identifier.length;  
      var tags = document.getElementsByTagName(tagName);  
 
      for (var i=0; i < tags.length; i++) {  
        var tempString = tags[i].id;  
        if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {  
          return tags[i];  
        }  
      }  
      return null;  
    }  
</script>  
 
 


Using the $find function on Firefox returns a reference to the Rad editor instance. However I get nothing back when doing this from IE.

Can you help? Is there an easier way to set text in the rad editor for a specific page?

1 Answer, 1 is accepted

Sort by
0
Stanimir
Telerik team
answered on 12 Dec 2008, 12:57 PM
Hi Tom.S,

In our online Knowledge Base you can find an article called How to execute custom code called on RadEditor's events.
http://www.telerik.com/support/kb/aspnet-ajax/sharepoint/how-to-execute-custom-code-called-on-radeditor-s-events.aspx

I think that you might find this helpful.


Regards,
Stanimir
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
WebParts for SharePoint
Asked by
Tom.S
Top achievements
Rank 1
Answers by
Stanimir
Telerik team
Share this question
or