How to make a field readonly on ui page ?

shabbir5
Tera Guru

How to make a field readonly onloading on a ui page 

Source<input type="text" id="selectDesc" readonly="true"></input>

tried this but not working

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can make it like this

HTML:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
 
    <html>
    <body onload="makeReadonly()">

Source<input type="text" id="selectDesc" readonly="true"></input>

</body>
    </html>
        
</j:jelly>

Client Script:

function makeReadonly(){
    
    var a= document.getElementById('selectDesc');
    a.setAttribute('disabled','true');

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Narsing1
Mega Sage

You can't type anything if you make readonly="true".  The above statement will work, but it still shows like a normal text box.

You need to use the below statement to completely make it as readonly.

<input type="text" id="selectDesc" disabled="true"></input>

Readonly (You can't type anything, but it still shows as normal textbox)

find_real_file.png

Disabled

find_real_file.png

Please mark it as correct answer if it helps.

Thanks,

Narsing

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can make it like this

HTML:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
 
    <html>
    <body onload="makeReadonly()">

Source<input type="text" id="selectDesc" readonly="true"></input>

</body>
    </html>
        
</j:jelly>

Client Script:

function makeReadonly(){
    
    var a= document.getElementById('selectDesc');
    a.setAttribute('disabled','true');

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader