Element.Forms

docs

This script has helpers for managing text selection and manipulation in form elements. Eventually I expect more form functionality to get added, but for now, its all about the kind of stuff that wysiwyg editors need to insert html around selected text and that sort of thing.

NOTE Since these examples are all about selections and caret locations, I can't have code examples that you click to execute (because this will change the focus).

Element.getTextInRange

Returns the value of the text within a given range in the input.

text in range (click the input to execute):

Element.getSelectedText

Gets the text that is currently selected.

selected text (select some text to execute):

Element.getSelectedRange

Gets the range that is selected.

getSelectedRange: (select some text to execute)

Element.selectRange

Selects a range of text.

selectRange (click to execute; this example passes in an array [2,5]):

Element.insertAtCursor

Insert text at the cursor location.

insertAtCursor (click anywhere to insert the example):

Element.insertAroundCursor

Wraps text with the given strings.

insertAroundCursor (select some text or click anywhere to insert "<" and ">" around the text):

Element.tidy

Removes MS-Word style non-ASCI characters from an input. See also String.tidy.

$('tidyExample').tidy();
//input value is now "'...'"
execute this code

cnet-libraries/04-element/00-element.forms.txt · Last modified: 2008/11/17 23:25