Add floating label to read only textbox in EJ2 JavaScript Textbox control

15 May 20236 minutes to read

You can achieve floating label for read-only textboxes by adding/removing e-label-top and e-label-bottom classes to the label element

In this sample, click the update value button to fill the read-only textbox with value and float a label.


function checkFloatingLabel(id) {
    var inputElement = document.getElementById(id);
    var labelElement = inputElement.parentElement.querySelector('.e-float-text');
    if (inputElement.value !== '') {
    else {
var inputField = document.getElementById('myText');
document.getElementById('valuebtn').onclick = function () {
    document.getElementsByClassName('myField')[0].value = '10';
document.getElementById('removebtn').addEventListener('click', function () {
    document.getElementsByClassName('myField')[0].value = '';
<!DOCTYPE html>
<html lang="en">

    <title>Essential JS 2 TextBox</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 TextBox Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//" rel="stylesheet" />
    <link href="//" rel="stylesheet" />
    <link href="//" rel="stylesheet" />
    <link href="index.css" rel="stylesheet" />
    <script src=""></script>
    <script src="systemjs.config.js"></script>
<script src="" type ="text/javascript"></script>
    <div id='loader'>Loading....</div>
    <div id='container' class="text_value">
        <div id="input-container"></div>

        <div class="row">
            <div class="col-xs-6 col-sm-6 col-lg-6 col-md-6">
                <div class="e-float-input">
                    <input class="e-input myField" id="myText" name="readonlyAttr"  type="text" readOnly>
                    <span class="e-float-line"></span>
                    <label class="e-float-text">Enter value</label>
        <div class="row">
            <div class="col-xs-10 col-sm-10 col-lg-10 col-md-10">
                <button class="e-btn update_value" id='valuebtn' >Set value</button>
                <button class="e-btn remove_value" id='removebtn' >Remove value</button>


var ele = document.getElementById('container');
if(ele) { = "visible";
<script src="index.js" type="text/javascript"></script>
#container {
    visibility: hidden;
  #loader {
    color: #008cff;
    font-family: 'Helvetica Neue','calibiri';
    font-size: 14px;
    height: 40px;
    left: 45%;
    position: absolute;
    top: 45%;
    width: 30%;
.update_value, .remove_value {
    margin-top: 20px;

.remove_value {
    margin-left: 10px;

.text_value {
    visibility: visible;
    box-sizing: border-box;
    margin: 0 auto;
    padding: 20px 10px;
    width: 260px;