You are here: Reference > JavaScript > client-side > event handling > methods > initTextEvent (event)
initTextEvent method (event)
9 | ||||
Initializes an event object created by the createEvent method with type of 'TextEvent'.
An event object created by the createEvent method with type of 'TextEvent' implements the TextEvent interface.
After initialization, the event can be dispatched with the dispatchEvent method.
In Internet Explorer before version 9, use the createEventObject method to create a new event object and the fireEvent method to dispatch it.
Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Required. String that specifies the name (type) of the event to initialize.
This parameter is case sensitive! Sets the type property of the event object.
For a complete list of events, see the page for Events in JavaScript.
The initTextEvent method is appropriate for initialization of TextEvent types principally, for other events, use the type-specific initialization methods.
Note: custom event names are also allowed.
Events represented by the TextEvent interface: |
|||||||||||||||||||||||
Required. Boolean that specifies whether the event can bubble or not. Sets the bubbles property of the event object.
One of the following values:
|
|||||||||||||||||||||||
Required. Boolean that specifies whether the event can be canceled or not. Sets the cancelable property of the event object.
One of the following values:
|
|||||||||||||||||||||||
Required. Reference to the window object in which the event is supposed to have occurred. Sets the view property of the event object. | |||||||||||||||||||||||
Required. String that specifies the text data for the event. Sets the data property of the event object. | |||||||||||||||||||||||
Required in Internet Explorer, not supported and omitted in Safari and Google Chrome. Integer that specifies the input mode for the text. | |||||||||||||||||||||||
Required in Internet Explorer, not supported and omitted in Safari and Google Chrome. String that specifies the locale name of the text. |
Return value:
This method has no return value.
Example HTML code 1:
This example illustrates the use of the initTextEvent method:
|
||||
<head> <script type="text/javascript"> function Init () { var textarea = document.getElementById ("textarea"); if (textarea.addEventListener) { // Google Chrome and Safari textarea.addEventListener ('textInput', OnTextInput, false); // Internet Explorer from version 9 textarea.addEventListener ("textinput", OnTextInput, false); } } function InsertText () { try { var textEvent = document.createEvent('TextEvent'); textEvent.initTextEvent ('textInput', true, true, null, "New text", 9, "en-US"); var textarea = document.getElementById ("textarea"); textarea.selectionStart = 0; textarea.selectionEnd = 0; textarea.dispatchEvent(textEvent); } catch (e) { alert ("Your browser does not support this example!"); } } function OnTextInput (event) { alert ("The inserted content: " + event.data); } </script> </head> <body onload="Init ();"> <textarea id="textarea">Textarea</textarea> <button onclick="InsertText ()">Insert text at the front of the textarea</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
event
createEvent
initEvent
initDragEvent
initKeyEvent
initMessageEvent
initMouseEvent
initMutationEvent
initOverflowEvent
initUIEvent
createEvent
initEvent
initDragEvent
initKeyEvent
initMessageEvent
initMouseEvent
initMutationEvent
initOverflowEvent
initUIEvent
External links:
User Contributed Comments