- FocusIn method
- FocusOut method
- GetPersistData method
Contact Support
Methods in EJ2 JavaScript TextArea Control
25 Mar 20249 minutes to read
This section outlines the methods available for interacting with the TextArea control.
FocusIn method
The focusIn method in the TextArea, is used to set focus to the textarea element, enabling user interaction.
By calling the focusIn
method, you can programmatically set focus to the TextArea control, allowing users to interact with it via keyboard input or other means.
// Initialize the TextArea control.
var textareaObj = new ej.inputs.TextArea({
placeholder: 'Enter your comments'
});
// Render initialized TextArea.
textareaObj.appendTo('#default');
document.getElementById('btn').onclick = function () {
// use focusIn method to focus TextArea
textareaObj.focusIn();
};
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 TextArea</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Essential JS 2 TextArea Components">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='container'>
<div class='wrap'>
<div id="input-container">
<textarea id="default"></textarea>
</div>
<div>
<button id="btn">Focus-in</button>
</div>
</div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>
FocusOut method
The focusOut method in the TextArea control is used to remove focus from the textarea element, ending user interaction.
This method is beneficial for scenarios where user need to programmatically remove focus from the TextArea control, such as after completing a specific task or when navigating to another element in the application.
// Initialize the TextArea control.
var textareaObj = new ej.inputs.TextArea({
placeholder: 'Enter your comments'
});
// Render initialized TextArea.
textareaObj.appendTo('#default');
document.getElementById('btn').onclick = function () {
// use focusOut method to remove focus from TextArea
textareaObj.focusOut();
};
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 TextArea</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Essential JS 2 TextArea Components">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='container'>
<div class='wrap'>
<div id="input-container">
<textarea id="default"></textarea>
</div>
<div>
<button id="btn">Focus-Out</button>
</div>
</div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>
GetPersistData method
The getPersistData method in the TextArea control retrieves the properties that need to be maintained in the persisted state.
This method returns an object containing the properties to be persisted, which can include various configuration options and state information of the TextArea control.
// Initialize the TextArea control.
var textareaObj = new ej.inputs.TextArea({
placeholder: 'Enter your comments'
});
// Render initialized TextArea.
textareaObj.appendTo('#default');
document.getElementById('btn').onclick = function () {
// use getPersistData method in TextArea
var data = textareaObj.getPersistData();
};
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 TextArea</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Essential JS 2 TextArea Components">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/29.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='container'>
<div class='wrap'>
<div id="input-container">
<textarea id="default"></textarea>
</div>
<div>
<button id="btn">Get Persist-data</button>
</div>
</div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>