Having trouble getting help?
Contact Support
Contact Support
Placeholder in EJ2 JavaScript OTP Input control
18 Jul 20245 minutes to read
The placeholder in OTP Input specifies the text that is shown as a hint or placeholder until the user enters a value in the input field. It acts as a guidance for the users regarding the expected input format or purpose of the input field.
You can set the placeholder text by using the placeholder property. Additionally, when providing a single character as the placeholder value all input fields within the OTP Input control will display the same character.
// Initializes the OTP Input control
var otpInput = new ej.inputs.OtpInput({
placeholder: "x"
});
// Render initialized OTP Input.
otpInput.appendTo('#default_otp');
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 - OTP Input</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="description" content="Essential JS 2">
<meta name="author" content="Syncfusion">
<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" />
<!--style reference from app-->
<link href="index.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' style="width: 350px;">
<div id="default_otp"></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>
#container {
visibility: hidden;
margin: 50px auto;
width: 350px;
}
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
When a placeholder with multiple placeholder characters is provided each input field will display characters from the placeholder string in sequence based on the available OTP input length.
// Initializes the OTP Input control
var otpInput = new ej.inputs.OtpInput({
placeholder: "wxyz"
});
// Render initialized OTP Input.
otpInput.appendTo('#default_otp');
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 - OTP Input</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="description" content="Essential JS 2">
<meta name="author" content="Syncfusion">
<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" />
<!--style reference from app-->
<link href="index.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' style="width: 350px;">
<div id="default_otp"></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>
#container {
visibility: hidden;
margin: 50px auto;
width: 350px;
}
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}