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

Getting text in javascript function

1 Answer 39 Views
Editor
This is a migrated thread and some comments may be shown as answers.
RMC Research
Top achievements
Rank 1
RMC Research asked on 06 Sep 2013, 02:51 PM
I have a RedEditor with the ID radEditor1 and the following javascript function:
// Character and Word Counter for Telerik RadEditor
//   Parameters:
//     ID of the RadEditor
//     Maximum number of words allowed
//     Returns false if maxWords is exceeded, true otherwise
 
function LimitWordCount(editorId, maxWords)
{
    var content = $find(editorId).get_text();
    var words = 0;
    var chars = 0;
    LimitWordCount = true;
    if (content) {
        punctRegX = /[!\.?;,:&_\-\-\{\}\[\]\(\)~#'"]/g;
        content = content.replace(punctRegX, "");
        if (content) {
            splitRegX = /\s+/;
            var array = content.split(splitRegX);
            words = array.length;
            chars = content.length;
        }
    }
    if (words > maxWords) {
        alert("Cannot exceed maximum word count.  Please shorten text.\nTo undo a paste, click the undo button at the top of the text area.")
        LimitWordCount = false;
    }
}

I call this function from the following link in a formview:
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Save" CssClass="linkbutton" OnClientClick='LimitWordCount("RadEditor1", 30)' />

When the javascript is hit, $find(editorId) returns null.

How would I get the text in this instance?  I have tried all the examples I can find, but all return null or give some other error. 

Help is appreciated!

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 10 Sep 2013, 12:36 PM
Hello,

I tested the provided code/markup and I was unable to reproduce the problem. You can see my test in the following video: http://screencast.com/t/YYjCwX8KCp. Am I missing something?

Please, test the attached project and if it works use it as a base to implement your scenario.

Best regards,
Rumen
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Editor
Asked by
RMC Research
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or